From 93895b54f7c638c71db4dd6c3a60f85fa3a75bdf Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Mon, 20 May 2024 11:38:39 -0600 Subject: [PATCH 1/9] add sparse pack wishlist items --- src/interface/sparse_pack.hpp | 44 ++++++++++++++++++++++++----------- tst/unit/test_sparse_pack.cpp | 3 +++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/interface/sparse_pack.hpp b/src/interface/sparse_pack.hpp index 80301a316d0d..cc5335674b08 100644 --- a/src/interface/sparse_pack.hpp +++ b/src/interface/sparse_pack.hpp @@ -160,36 +160,54 @@ class SparsePack : public SparsePackBase { } // Host Bound overloads - KOKKOS_INLINE_FUNCTION int GetLowerBoundHost(const int b) const { + inline int GetLowerBoundHost(const int b) const { return (flat_ && (b > 0)) ? (bounds_h_(1, b - 1, nvar_) + 1) : 0; } - KOKKOS_INLINE_FUNCTION int GetUpperBoundHost(const int b) const { - return bounds_h_(1, b, nvar_); - } + inline int GetUpperBoundHost(const int b) const { return bounds_h_(1, b, nvar_); } - KOKKOS_INLINE_FUNCTION int GetLowerBoundHost(const int b, PackIdx idx) const { + inline int GetLowerBoundHost(const int b, PackIdx idx) const { static_assert(sizeof...(Ts) == 0); return bounds_h_(0, b, idx.VariableIdx()); } - KOKKOS_INLINE_FUNCTION int GetUpperBoundHost(const int b, PackIdx idx) const { + inline int GetUpperBoundHost(const int b, PackIdx idx) const { static_assert(sizeof...(Ts) == 0); return bounds_h_(1, b, idx.VariableIdx()); } template ::value)> - KOKKOS_INLINE_FUNCTION int GetLowerBoundHost(const int b, const TIn &) const { + inline int GetLowerBoundHost(const int b, const TIn &) const { const int vidx = GetTypeIdx::value; return bounds_h_(0, b, vidx); } template ::value)> - KOKKOS_INLINE_FUNCTION int GetUpperBoundHost(const int b, const TIn &) const { + inline int GetUpperBoundHost(const int b, const TIn &) const { const int vidx = GetTypeIdx::value; return bounds_h_(1, b, vidx); } + // Number of components of a variable on a block + template + KOKKOS_INLINE_FUNCTION int GetSize(const int b, const T &t) const { + return GetUpperBound(b, t) - GetLowerBound(b, t) + 1; + } + template + inline int GetSizeHost(const int b, const T &t) const { + return GetUpperBoundHost(b, t) - GetLowerBoundHost(b, t) + 1; + } + + // Index in pack + template ::value)> + KOKKOS_INLINE_FUNCTION int GetIndex(const int b, const TIn &var) const { + return GetLowerBound(b, var) + var.idx; + } + template ::value)> + inline int GetIndexHost(const int b, const TIn &var) const { + return GetLowerBoundHost(b, var) + var.idx; + } + /* Usage: * Contains(b, v1(), v2(), v3()) * @@ -213,19 +231,17 @@ class SparsePack : public SparsePackBase { return (... && Contains(b, Args())); } // Host versions - KOKKOS_INLINE_FUNCTION bool ContainsHost(const int b) const { - return GetUpperBoundHost(b) >= 0; - } + inline bool ContainsHost(const int b) const { return GetUpperBoundHost(b) >= 0; } template - KOKKOS_INLINE_FUNCTION bool ContainsHost(const int b, const T t) const { + inline bool ContainsHost(const int b, const T t) const { return GetUpperBoundHost(b, t) >= 0; } template - KOKKOS_INLINE_FUNCTION bool ContainsHost(const int b, Args... args) const { + inline bool ContainsHost(const int b, Args... args) const { return (... && ContainsHost(b, args)); } template 0)> - KOKKOS_INLINE_FUNCTION bool ContainsHost(const int b) const { + inline bool ContainsHost(const int b) const { return (... && ContainsHost(b, Args())); } diff --git a/tst/unit/test_sparse_pack.cpp b/tst/unit/test_sparse_pack.cpp index 180114386671..106dc97befc2 100644 --- a/tst/unit/test_sparse_pack.cpp +++ b/tst/unit/test_sparse_pack.cpp @@ -217,6 +217,9 @@ TEST_CASE("Test behavior of sparse packs", "[SparsePack]") { REQUIRE(pack.ContainsHost(2, v5())); REQUIRE(!pack.ContainsHost(2, v1(), v3(), v5())); REQUIRE(pack.ContainsHost(2)); + REQUIRE(pack.GetSizeHost(2, v1()) == 1); + REQUIRE(pack.GetSizeHost(2, v3()) == 0); + REQUIRE(pack.GetSizeHost(1, v3()) == 3); } THEN("A sparse pack correctly loads this data and can be read from v3 on all " From ea75b7a1aa294f48377fb7791e7f2a11335eca4e Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Mon, 20 May 2024 11:41:42 -0600 Subject: [PATCH 2/9] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f80b56f73e3e..4224702f0da9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Current develop ### Added (new features/APIs/variables/...) +- [[PR1081]](https://github.com/parthenon-hpc-lab/parthenon/pull/1081) Add GetSize and GetIndex to sparse pack - [[PR1020]](https://github.com/parthenon-hpc-lab/parthenon/pull/1020) Add bi- and trilinear interpolation routines - [[PR 1026]](https://github.com/parthenon-hpc-lab/parthenon/pull/1026) Particle BCs without relocatable device code - [[PR 1037]](https://github.com/parthenon-hpc-lab/parthenon/pull/1037) Add SwarmPacks From d0efcd1d3183caf3768cf78f2bca4d0f40f65537 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Tue, 21 May 2024 08:18:18 -0600 Subject: [PATCH 3/9] MPI_Request_free instead of just setting var to null --- src/interface/swarm_comms.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/interface/swarm_comms.cpp b/src/interface/swarm_comms.cpp index 67bff0a69565..ed797331eddf 100644 --- a/src/interface/swarm_comms.cpp +++ b/src/interface/swarm_comms.cpp @@ -644,7 +644,9 @@ void Swarm::ResetCommunication() { #ifdef MPI_PARALLEL for (int n = 0; n < pmb->neighbors.size(); n++) { NeighborBlock &nb = pmb->neighbors[n]; - vbswarm->bd_var_.req_send[nb.bufid] = MPI_REQUEST_NULL; + if (vbswarm->bd_var_.req_send[nb.bufid] != MPI_REQUEST_NULL) { + MPI_Request_Free(vbswarm->bd_var_.req_send[nb.bufid]); + } } #endif From e207e630790988c19f2f04caed8dd67be2995719 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Tue, 21 May 2024 08:21:25 -0600 Subject: [PATCH 4/9] CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f80b56f73e3e..c5faad1ecba2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ## Current develop ### Added (new features/APIs/variables/...) -- [[PR1020]](https://github.com/parthenon-hpc-lab/parthenon/pull/1020) Add bi- and trilinear interpolation routines +- [[PR 1084]](https://github.com/parthenon-hpc-lab/parthenon/pull/1084) Properly free swarm boundary MPI requests +- [[PR 1020]](https://github.com/parthenon-hpc-lab/parthenon/pull/1020) Add bi- and trilinear interpolation routines - [[PR 1026]](https://github.com/parthenon-hpc-lab/parthenon/pull/1026) Particle BCs without relocatable device code - [[PR 1037]](https://github.com/parthenon-hpc-lab/parthenon/pull/1037) Add SwarmPacks - [[PR 1068]](https://github.com/parthenon-hpc-lab/parthenon/pull/1068) Add ability to dump sparse pack contents as a string From 1ab803370554bd1312754425902536e55e2d9665 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Tue, 21 May 2024 08:22:11 -0600 Subject: [PATCH 5/9] pointer --- src/interface/swarm_comms.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/swarm_comms.cpp b/src/interface/swarm_comms.cpp index ed797331eddf..2639d042dfc9 100644 --- a/src/interface/swarm_comms.cpp +++ b/src/interface/swarm_comms.cpp @@ -645,7 +645,7 @@ void Swarm::ResetCommunication() { for (int n = 0; n < pmb->neighbors.size(); n++) { NeighborBlock &nb = pmb->neighbors[n]; if (vbswarm->bd_var_.req_send[nb.bufid] != MPI_REQUEST_NULL) { - MPI_Request_Free(vbswarm->bd_var_.req_send[nb.bufid]); + MPI_Request_Free(&(vbswarm->bd_var_.req_send[nb.bufid])); } } #endif From 4d133ed5ee35815fb0aa9426853a663855f5e872 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Tue, 21 May 2024 08:45:47 -0600 Subject: [PATCH 6/9] I cant compile in my head :( --- src/interface/swarm_comms.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/swarm_comms.cpp b/src/interface/swarm_comms.cpp index 2639d042dfc9..d63a4e75a23a 100644 --- a/src/interface/swarm_comms.cpp +++ b/src/interface/swarm_comms.cpp @@ -645,7 +645,7 @@ void Swarm::ResetCommunication() { for (int n = 0; n < pmb->neighbors.size(); n++) { NeighborBlock &nb = pmb->neighbors[n]; if (vbswarm->bd_var_.req_send[nb.bufid] != MPI_REQUEST_NULL) { - MPI_Request_Free(&(vbswarm->bd_var_.req_send[nb.bufid])); + MPI_Request_free(&(vbswarm->bd_var_.req_send[nb.bufid])); } } #endif From 921f19a24045a151863516515912584896bacf23 Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Tue, 21 May 2024 10:04:58 -0600 Subject: [PATCH 7/9] remove inlines when not needed --- src/interface/sparse_pack.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/interface/sparse_pack.hpp b/src/interface/sparse_pack.hpp index cc5335674b08..f1c1fa1846c3 100644 --- a/src/interface/sparse_pack.hpp +++ b/src/interface/sparse_pack.hpp @@ -160,30 +160,30 @@ class SparsePack : public SparsePackBase { } // Host Bound overloads - inline int GetLowerBoundHost(const int b) const { + int GetLowerBoundHost(const int b) const { return (flat_ && (b > 0)) ? (bounds_h_(1, b - 1, nvar_) + 1) : 0; } - inline int GetUpperBoundHost(const int b) const { return bounds_h_(1, b, nvar_); } + int GetUpperBoundHost(const int b) const { return bounds_h_(1, b, nvar_); } - inline int GetLowerBoundHost(const int b, PackIdx idx) const { + int GetLowerBoundHost(const int b, PackIdx idx) const { static_assert(sizeof...(Ts) == 0); return bounds_h_(0, b, idx.VariableIdx()); } - inline int GetUpperBoundHost(const int b, PackIdx idx) const { + int GetUpperBoundHost(const int b, PackIdx idx) const { static_assert(sizeof...(Ts) == 0); return bounds_h_(1, b, idx.VariableIdx()); } template ::value)> - inline int GetLowerBoundHost(const int b, const TIn &) const { + int GetLowerBoundHost(const int b, const TIn &) const { const int vidx = GetTypeIdx::value; return bounds_h_(0, b, vidx); } template ::value)> - inline int GetUpperBoundHost(const int b, const TIn &) const { + int GetUpperBoundHost(const int b, const TIn &) const { const int vidx = GetTypeIdx::value; return bounds_h_(1, b, vidx); } @@ -194,7 +194,7 @@ class SparsePack : public SparsePackBase { return GetUpperBound(b, t) - GetLowerBound(b, t) + 1; } template - inline int GetSizeHost(const int b, const T &t) const { + int GetSizeHost(const int b, const T &t) const { return GetUpperBoundHost(b, t) - GetLowerBoundHost(b, t) + 1; } @@ -204,7 +204,7 @@ class SparsePack : public SparsePackBase { return GetLowerBound(b, var) + var.idx; } template ::value)> - inline int GetIndexHost(const int b, const TIn &var) const { + int GetIndexHost(const int b, const TIn &var) const { return GetLowerBoundHost(b, var) + var.idx; } @@ -231,17 +231,17 @@ class SparsePack : public SparsePackBase { return (... && Contains(b, Args())); } // Host versions - inline bool ContainsHost(const int b) const { return GetUpperBoundHost(b) >= 0; } + bool ContainsHost(const int b) const { return GetUpperBoundHost(b) >= 0; } template - inline bool ContainsHost(const int b, const T t) const { + bool ContainsHost(const int b, const T t) const { return GetUpperBoundHost(b, t) >= 0; } template - inline bool ContainsHost(const int b, Args... args) const { + bool ContainsHost(const int b, Args... args) const { return (... && ContainsHost(b, args)); } template 0)> - inline bool ContainsHost(const int b) const { + bool ContainsHost(const int b) const { return (... && ContainsHost(b, Args())); } From 4f1edee66d2041ad8adade6e914d110f38b140f2 Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Tue, 21 May 2024 14:11:15 -0600 Subject: [PATCH 8/9] add get_max_nij --- src/utils/index_split.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/index_split.hpp b/src/utils/index_split.hpp index 2c560d5e247c..4f4891614802 100644 --- a/src/utils/index_split.hpp +++ b/src/utils/index_split.hpp @@ -91,8 +91,12 @@ class IndexSplit { KOKKOS_INLINE_FUNCTION int get_max_ni() const { return ibe_entire_ + 1; } // TODO(@jdolence) these overestimate max size...should probably fix + KOKKOS_INLINE_FUNCTION int get_max_nj() const { return (jbe_entire_ + 1) / njp_ + 1; } + KOKKOS_INLINE_FUNCTION int get_max_nk() const { return (kbe_entire_ + 1) / nkp_ + 1; } + KOKKOS_INLINE_FUNCTION + int get_max_nij() const { return get_max_ni() * get_max_nj(); } // inner_size could be used to find the bounds for a loop that is collapsed over // 1, 2, or 3 dimensions by providing the right starting and stopping indices template From 604e97f1d7a0ec733fd60c3d10f3082a0dfa5592 Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Tue, 21 May 2024 14:12:26 -0600 Subject: [PATCH 9/9] sneak it in --- src/utils/index_split.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/index_split.hpp b/src/utils/index_split.hpp index 4f4891614802..e9a5f4b441bd 100644 --- a/src/utils/index_split.hpp +++ b/src/utils/index_split.hpp @@ -1,5 +1,5 @@ //======================================================================================== -// (C) (or copyright) 2023. Triad National Security, LLC. All rights reserved. +// (C) (or copyright) 2023-2024. Triad National Security, LLC. All rights reserved. // // This program was produced under U.S. Government contract 89233218CNA000001 for Los // Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC