From 3fb2531e3ae74e37157c3d7beebfe8c9573cb8c7 Mon Sep 17 00:00:00 2001 From: Maciej Waruszewski Date: Mon, 23 Mar 2026 15:29:44 -0600 Subject: [PATCH 1/2] Set vertical bounds to prevent accesses outside of halo region --- components/omega/src/ocn/VertCoord.cpp | 39 ++++++++++++++++++++++++++ components/omega/src/ocn/VertCoord.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/components/omega/src/ocn/VertCoord.cpp b/components/omega/src/ocn/VertCoord.cpp index 027006d1164c..1c1256368236 100644 --- a/components/omega/src/ocn/VertCoord.cpp +++ b/components/omega/src/ocn/VertCoord.cpp @@ -142,10 +142,12 @@ VertCoord::VertCoord(const std::string &Name_, //< [in] Name for new VertCoord NCellsSize = Decomp->NCellsSize; NEdgesOwned = Decomp->NEdgesOwned; + NEdgesHalo0 = Decomp->NEdgesHaloH(0); NEdgesAll = Decomp->NEdgesAll; NEdgesSize = Decomp->NEdgesSize; NVerticesOwned = Decomp->NVerticesOwned; + NVerticesHalo0 = Decomp->NVerticesHaloH(0); NVerticesAll = Decomp->NVerticesAll; NVerticesSize = Decomp->NVerticesSize; VertexDegree = Decomp->VertexDegree; @@ -626,6 +628,22 @@ void VertCoord::minMaxLayerEdge(Halo *MeshHalo) { LocMaxLayerEdgeBot(LocNEdgesAll) = -1; }); + // Set the [MinLayerEdgeBot, MaxLayerEdgeTop] range to be invalid + // on the outermost edges of the halo layer. + OMEGA_SCOPE(LocNEdgesHalo0, NEdgesHalo0); + // start from NEdgesHalo(0) to exclude any edges of the owned cells + parallelFor( + {NEdgesAll - NEdgesHalo0}, KOKKOS_LAMBDA(int EdgeOffset) { + const int IEdge = LocNEdgesHalo0 + EdgeOffset; + + // Is any cell on this edge an invalid (remote) cell ? + if (LocCellsOnEdge(IEdge, 0) == LocNEdgesAll || + LocCellsOnEdge(IEdge, 1) == LocNEdgesAll) { + LocMinLayerEdgeBot(IEdge) = LocNVertLayersP1; + LocMaxLayerEdgeTop(IEdge) = -1; + } + }); + MinLayerEdgeTopH = createHostMirrorCopy(MinLayerEdgeTop); MinLayerEdgeBotH = createHostMirrorCopy(MinLayerEdgeBot); MaxLayerEdgeTopH = createHostMirrorCopy(MaxLayerEdgeTop); @@ -708,6 +726,27 @@ void VertCoord::minMaxLayerVertex(Halo *MeshHalo) { LocMaxLayerVertexBot(LocNVerticesAll) = -1; }); + // Set the [MinLayerVertexBot, MaxLayerVertexTop] range to be invalid + // on the outermost vertices of the halo layer. + OMEGA_SCOPE(LocNVerticesHalo0, NVerticesHalo0); + // start from NVerticesHalo(0) to exclude any vertices of the owned cells + parallelFor( + {NVerticesAll - NVerticesHalo0}, KOKKOS_LAMBDA(int VertexOffset) { + const int IVertex = LocNVerticesHalo0 + VertexOffset; + + // Is any cell on this vertex an invalid (remote) cell ? + bool IsOuterMost = LocCellsOnVertex(IVertex, 0) == LocNVerticesAll; + for (int I = 1; I < LocVertexDegree; ++I) { + IsOuterMost = + IsOuterMost || LocCellsOnVertex(IVertex, I) == LocNVerticesAll; + } + + if (IsOuterMost) { + LocMinLayerVertexBot(IVertex) = LocNVertLayersP1; + LocMaxLayerVertexTop(IVertex) = -1; + } + }); + MinLayerVertexTopH = createHostMirrorCopy(MinLayerVertexTop); MinLayerVertexBotH = createHostMirrorCopy(MinLayerVertexBot); MaxLayerVertexTopH = createHostMirrorCopy(MaxLayerVertexTop); diff --git a/components/omega/src/ocn/VertCoord.h b/components/omega/src/ocn/VertCoord.h index d39d3676b225..d7afe16739be 100644 --- a/components/omega/src/ocn/VertCoord.h +++ b/components/omega/src/ocn/VertCoord.h @@ -59,9 +59,11 @@ class VertCoord { I4 NCellsAll; I4 NCellsSize; I4 NEdgesOwned; + I4 NEdgesHalo0; I4 NEdgesAll; I4 NEdgesSize; I4 NVerticesOwned; + I4 NVerticesHalo0; I4 NVerticesAll; I4 NVerticesSize; I4 VertexDegree; From 9f58f44893e55e32f2ae9472c8827ea07a347c59 Mon Sep 17 00:00:00 2001 From: Maciej Waruszewski Date: Mon, 6 Apr 2026 08:54:26 -0600 Subject: [PATCH 2/2] Use NCellsAll to look for invalid cells Co-authored-by: Brian O'Neill --- components/omega/src/ocn/VertCoord.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/omega/src/ocn/VertCoord.cpp b/components/omega/src/ocn/VertCoord.cpp index 1c1256368236..4de79abcc052 100644 --- a/components/omega/src/ocn/VertCoord.cpp +++ b/components/omega/src/ocn/VertCoord.cpp @@ -631,14 +631,15 @@ void VertCoord::minMaxLayerEdge(Halo *MeshHalo) { // Set the [MinLayerEdgeBot, MaxLayerEdgeTop] range to be invalid // on the outermost edges of the halo layer. OMEGA_SCOPE(LocNEdgesHalo0, NEdgesHalo0); + OMEGA_SCOPE(LocNCellsAll, NCellsAll); // start from NEdgesHalo(0) to exclude any edges of the owned cells parallelFor( {NEdgesAll - NEdgesHalo0}, KOKKOS_LAMBDA(int EdgeOffset) { const int IEdge = LocNEdgesHalo0 + EdgeOffset; // Is any cell on this edge an invalid (remote) cell ? - if (LocCellsOnEdge(IEdge, 0) == LocNEdgesAll || - LocCellsOnEdge(IEdge, 1) == LocNEdgesAll) { + if (LocCellsOnEdge(IEdge, 0) == LocNCellsAll || + LocCellsOnEdge(IEdge, 1) == LocNCellsAll) { LocMinLayerEdgeBot(IEdge) = LocNVertLayersP1; LocMaxLayerEdgeTop(IEdge) = -1; } @@ -729,16 +730,17 @@ void VertCoord::minMaxLayerVertex(Halo *MeshHalo) { // Set the [MinLayerVertexBot, MaxLayerVertexTop] range to be invalid // on the outermost vertices of the halo layer. OMEGA_SCOPE(LocNVerticesHalo0, NVerticesHalo0); + OMEGA_SCOPE(LocNCellsAll, NCellsAll); // start from NVerticesHalo(0) to exclude any vertices of the owned cells parallelFor( {NVerticesAll - NVerticesHalo0}, KOKKOS_LAMBDA(int VertexOffset) { const int IVertex = LocNVerticesHalo0 + VertexOffset; // Is any cell on this vertex an invalid (remote) cell ? - bool IsOuterMost = LocCellsOnVertex(IVertex, 0) == LocNVerticesAll; + bool IsOuterMost = LocCellsOnVertex(IVertex, 0) == LocNCellsAll; for (int I = 1; I < LocVertexDegree; ++I) { IsOuterMost = - IsOuterMost || LocCellsOnVertex(IVertex, I) == LocNVerticesAll; + IsOuterMost || LocCellsOnVertex(IVertex, I) == LocNCellsAll; } if (IsOuterMost) {