From 00a47c44de9c66f026b74d6ea41e961cea8a07d2 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Fri, 5 Jun 2020 16:03:35 -0400 Subject: [PATCH 1/3] fixed bad array sizes in local ocean arrays two ocean modules had local arrays that were not properly sized to accommodate the practice of using nCellsAll+1 (Edges, Vertices) as a location to represent non-existent cells, edges, vertices this commit extends the dimension by one for these arrays --- src/core_ocean/shared/mpas_ocn_mesh.F | 18 +++++++------- .../shared/mpas_ocn_tracer_advection_mono.F | 24 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/core_ocean/shared/mpas_ocn_mesh.F b/src/core_ocean/shared/mpas_ocn_mesh.F index 39e3976c13..2fa1ea18b4 100644 --- a/src/core_ocean/shared/mpas_ocn_mesh.F +++ b/src/core_ocean/shared/mpas_ocn_mesh.F @@ -459,15 +459,15 @@ subroutine ocn_meshCreate(domain) !{{{ boundaryCellTmp) allocate ( & - edgeMask(nVertLevels, nEdgesAll), & - cellMask(nVertLevels, nCellsAll), & - vertexMask(nVertLevels, nVerticesAll), & - boundaryEdge(nVertLevels, nEdgesAll), & - boundaryCell(nVertLevels, nCellsAll), & - boundaryVertex(nVertLevels, nVerticesAll), & - edgeSignOnCell(maxEdges, nCellsAll), & - edgeSignOnVertex(maxEdges, nVerticesAll), & - highOrderAdvectionMask(nVertLevels, nEdgesAll)) + edgeMask(nVertLevels, nEdgesAll+1), & + cellMask(nVertLevels, nCellsAll+1), & + vertexMask(nVertLevels, nVerticesAll+1), & + boundaryEdge(nVertLevels, nEdgesAll+1), & + boundaryCell(nVertLevels, nCellsAll+1), & + boundaryVertex(nVertLevels, nVerticesAll+1), & + edgeSignOnCell(maxEdges, nCellsAll+1), & + edgeSignOnVertex(maxEdges, nVerticesAll+1), & + highOrderAdvectionMask(nVertLevels, nEdgesAll+1)) do n = 1, nCellsAll do k = 1, nVertLevels diff --git a/src/core_ocean/shared/mpas_ocn_tracer_advection_mono.F b/src/core_ocean/shared/mpas_ocn_tracer_advection_mono.F index a6096e5d57..9efee519d5 100644 --- a/src/core_ocean/shared/mpas_ocn_tracer_advection_mono.F +++ b/src/core_ocean/shared/mpas_ocn_tracer_advection_mono.F @@ -231,17 +231,17 @@ subroutine ocn_tracer_advection_mono_tend(tend, tracers, layerThickness, & ! allocate temporary arrays !$omp master - allocate(tracerCur (nVertLevels ,nCells), & + allocate(tracerCur (nVertLevels ,nCells+1), & tracerMin (nVertLevels ,nCells), & tracerMax (nVertLevels ,nCells), & hNewInv (nVertLevels ,nCells), & hProv (nVertLevels ,nCells), & hProvInv (nVertLevels ,nCells), & - flxIn (nVertLevels ,nCells), & - flxOut (nVertLevels ,nCells), & - workTend (nVertLevels ,nCells), & - lowOrderFlx (nVertLevels+1,max(nCells,nEdges)), & - highOrderFlx(nVertLevels+1,max(nCells,nEdges))) + flxIn (nVertLevels ,nCells+1), & + flxOut (nVertLevels ,nCells+1), & + workTend (nVertLevels ,nCells+1), & + lowOrderFlx (nVertLevels+1,max(nCells,nEdges)+1), & + highOrderFlx(nVertLevels+1,max(nCells,nEdges)+1)) !$omp end master !$omp barrier @@ -291,7 +291,7 @@ subroutine ocn_tracer_advection_mono_tend(tend, tracers, layerThickness, & ! Extract current tracer and change index order to improve locality !$omp do schedule(runtime) - do iCell = 1, nCells + do iCell = 1, nCells+1 do k=1, nVertLevels tracerCur(k,iCell) = tracers(iTracer,k,iCell) end do ! k loop @@ -390,12 +390,11 @@ subroutine ocn_tracer_advection_mono_tend(tend, tracers, layerThickness, & call mpas_timer_stop('horiz flux') call mpas_timer_start('scale factor build') #endif - ! Need one halo of cells around owned cells - nCells = nCellsArray( 2 ) + ! Initialize flux arrays for all cells + nCells = nCellsArray(size(nCellsArray)) - ! Initialize flux arrays !$omp do schedule(runtime) - do iCell = 1, nCells + do iCell = 1, nCells+1 do k=1, nVertLevels workTend(k, iCell) = 0.0_RKIND flxIn (k, iCell) = 0.0_RKIND @@ -404,6 +403,9 @@ subroutine ocn_tracer_advection_mono_tend(tend, tracers, layerThickness, & end do ! iCell loop !$omp end do + ! Need one halo of cells around owned cells + nCells = nCellsArray( 2 ) + !$omp do schedule(runtime) do iCell = 1, nCells invAreaCell1 = 1.0_RKIND / areaCell(iCell) From 70a5b7cbda37d7a71dbbd5f9898d5e15acc58566 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Mon, 8 Jun 2020 16:01:55 -0400 Subject: [PATCH 2/3] fixed initialization loops for modified mesh local array sizes - previous commit changed array sizes in ocn mesh routine but did not change following initialization loops. --- src/core_ocean/shared/mpas_ocn_mesh.F | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core_ocean/shared/mpas_ocn_mesh.F b/src/core_ocean/shared/mpas_ocn_mesh.F index 2fa1ea18b4..5b55e1f0cf 100644 --- a/src/core_ocean/shared/mpas_ocn_mesh.F +++ b/src/core_ocean/shared/mpas_ocn_mesh.F @@ -469,20 +469,20 @@ subroutine ocn_meshCreate(domain) !{{{ edgeSignOnVertex(maxEdges, nVerticesAll+1), & highOrderAdvectionMask(nVertLevels, nEdgesAll+1)) - do n = 1, nCellsAll + do n = 1, nCellsAll+1 do k = 1, nVertLevels cellMask(k, n) = real(cellMaskTmp(k, n), RKIND) boundaryCell(k, n) = real(boundaryCellTmp(k, n), RKIND) end do end do - do n = 1, nCellsAll + do n = 1, nCellsAll+1 do k = 1, maxEdges edgeSignOnCell(k, n) = real(edgeSignOnCellTmp(k, n), RKIND) end do end do - do n = 1, nEdgesAll + do n = 1, nEdgesAll+1 do k = 1, nVertLevels edgeMask(k, n) = real(edgeMaskTmp(k, n), RKIND) boundaryEdge(k, n) = real(boundaryEdgeTmp(k, n), RKIND) @@ -491,14 +491,14 @@ subroutine ocn_meshCreate(domain) !{{{ end do end do - do n = 1, nVerticesAll + do n = 1, nVerticesAll+1 do k = 1, nVertLevels vertexMask(k, n) = real(vertexMaskTmp(k, n), RKIND) boundaryVertex(k, n) = real(boundaryVertexTmp(k, n), RKIND) end do end do - do n = 1, nVerticesAll + do n = 1, nVerticesAll+1 do k = 1, vertexDegree edgeSignOnVertex(k, n) = real(edgeSignOnVertexTmp(k, n), RKIND) end do From c1aaf41f4d19df61e98d072ed87cdad472484e5d Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Mon, 8 Jun 2020 16:08:47 -0400 Subject: [PATCH 3/3] second fix to mesh array initialization loops - previous commit missed some similar loops in the update routine --- src/core_ocean/shared/mpas_ocn_mesh.F | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core_ocean/shared/mpas_ocn_mesh.F b/src/core_ocean/shared/mpas_ocn_mesh.F index 5b55e1f0cf..7588a69a04 100644 --- a/src/core_ocean/shared/mpas_ocn_mesh.F +++ b/src/core_ocean/shared/mpas_ocn_mesh.F @@ -1045,20 +1045,20 @@ subroutine ocn_meshUpdateFields(domain) !{{{ call mpas_pool_get_array(meshPool, 'boundaryCell', & boundaryCellTmp) - do n = 1, nCellsAll + do n = 1, nCellsAll+1 do k = 1, nVertLevels cellMask(k, n) = real(cellMaskTmp(k, n), RKIND) boundaryCell(k, n) = real(boundaryCellTmp(k, n), RKIND) end do end do - do n = 1, nCellsAll + do n = 1, nCellsAll+1 do k = 1, maxEdges edgeSignOnCell(k, n) = real(edgeSignOnCellTmp(k, n), RKIND) end do end do - do n = 1, nEdgesAll + do n = 1, nEdgesAll+1 do k = 1, nVertLevels edgeMask(k, n) = real(edgeMaskTmp(k, n), RKIND) boundaryEdge(k, n) = real(boundaryEdgeTmp(k, n), RKIND) @@ -1067,14 +1067,14 @@ subroutine ocn_meshUpdateFields(domain) !{{{ end do end do - do n = 1, nVerticesAll + do n = 1, nVerticesAll+1 do k = 1, nVertLevels vertexMask(k, n) = real(vertexMaskTmp(k, n), RKIND) boundaryVertex(k, n) = real(boundaryVertexTmp(k, n), RKIND) end do end do - do n = 1, nVerticesAll + do n = 1, nVerticesAll+1 do k = 1, vertexDegree edgeSignOnVertex(k, n) = & real(edgeSignOnVertexTmp(k, n), RKIND)