From 4b331dbd34c91792e5211e04880f197d659318fd Mon Sep 17 00:00:00 2001 From: hayk Date: Thu, 26 Mar 2026 00:52:55 -0400 Subject: [PATCH 01/12] tile-based-sort --- src/framework/containers/particles_sort.cpp | 12 ++- src/global/utils/sorting.h | 86 ++++++++++++++------- 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/src/framework/containers/particles_sort.cpp b/src/framework/containers/particles_sort.cpp index 2fd0e6011..73d21bb6e 100644 --- a/src/framework/containers/particles_sort.cpp +++ b/src/framework/containers/particles_sort.cpp @@ -189,10 +189,14 @@ namespace ntt { array_t cell_indices { "cell_indices", npart() }; - Kokkos::parallel_for( - "FillCellIndices", - rangeActiveParticles(), - sort::PositionToCellIndex { i1, i2, i3, tag, cell_indices, nx2, nx3, total_cells }); + Kokkos::parallel_for("FillCellIndices", + rangeActiveParticles(), + sort::PositionToTileIndex { i1, + i2, + i3, + tag, + cell_indices, + grid.n_active() }); const auto slice = range_tuple_t(0, npart()); using sorter_op_t = Kokkos::BinOp1D; diff --git a/src/global/utils/sorting.h b/src/global/utils/sorting.h index c0639d81a..5c4be355e 100644 --- a/src/global/utils/sorting.h +++ b/src/global/utils/sorting.h @@ -4,7 +4,7 @@ * @implements * - sort::BinBool<> * - sort::BinTag<> - * - sort::PositionToCellIndex<> + * - sort::PositionToTileIndex<> * @namespaces: * - sort:: * @note BinBool sorts by boolean values "true" then "false" @@ -14,7 +14,6 @@ #ifndef GLOBAL_UTILS_SORTING_H #define GLOBAL_UTILS_SORTING_H -#include "enums.h" #include "global.h" #include "arch/kokkos_aliases.h" @@ -63,47 +62,80 @@ namespace sort { const int m_max_bins; }; - template - struct PositionToCellIndex { + template + struct PositionToTileIndex { const array_t i1, i2, i3; const array_t tag; - array_t cell_indices; - ncells_t nx2, nx3, total_cells; - - PositionToCellIndex(const array_t& i1, - const array_t& i2, - const array_t& i3, - const array_t& tag, - array_t& cell_indices, - ncells_t nx2, - ncells_t nx3, - ncells_t total_cells) + array_t tile_indices; + ncells_t tile_size; + array_t num_ppt; + + ncells_t ntx2, ntx3; + ncells_t total_tiles; + + PositionToTileIndex(const array_t& i1, + const array_t& i2, + const array_t& i3, + const array_t& tag, + array_t& tile_indices, + const std::vector ncells, + ncells_t tile_size = 1u, + array_t num_ppt = { "num_ppt", 0u }) : i1 { i1 } , i2 { i2 } , i3 { i3 } , tag { tag } - , cell_indices { cell_indices } - , nx2 { nx2 } - , nx3 { nx3 } - , total_cells { total_cells } {} + , tile_indices { tile_indices } + , tile_size { tile_size } + , num_ppt { num_ppt } { + raise::ErrorIf(ncells.size() >= static_cast(D), + "ncells size must match D", + HERE); + const auto ntx1 = static_cast(math::ceil( + static_cast(ncells[0]) / static_cast(tile_size))); + if constexpr (D == Dim::_1D) { + ntx2 = 1u; + ntx3 = 1u; + } else if constexpr (D == Dim::_2D) { + ntx2 = static_cast(math::ceil( + static_cast(ncells[1]) / static_cast(tile_size))); + ntx3 = 1u; + } else if constexpr (D == Dim::_3D) { + ntx2 = static_cast(math::ceil( + static_cast(ncells[1]) / static_cast(tile_size))); + ntx3 = static_cast(math::ceil( + static_cast(ncells[2]) / static_cast(tile_size))); + } else { + raise::Error("Wrong D in SortSpatially", HERE); + } + total_tiles = ntx1 * ntx2 * ntx3; + if constexpr (Count) { + raise::ErrorIf(num_ppt.extent(0) != total_tiles, + "num_ppt must have extent equal to total tiles", + HERE); + } + } Inline auto operator()(index_t p) const { if (tag(p) != ntt::ParticleTag::alive) { - cell_indices(p) = total_cells + 1u; + tile_indices(p) = total_tiles + 1u; } else { if constexpr (D == Dim::_1D) { - cell_indices(p) = static_cast(i1(p)); + tile_indices(p) = static_cast(i1(p)); } else if constexpr (D == Dim::_2D) { - cell_indices(p) = static_cast(i1(p)) * nx2 + - static_cast(i2(p)); + tile_indices(p) = static_cast(i1(p) / tile_size) * ntx2 + + static_cast(i2(p) / tile_size); } else if constexpr (D == Dim::_3D) { - cell_indices(p) = (static_cast(i1(p)) * nx2 + - static_cast(i2(p))) * - nx3 + - static_cast(i3(p)); + tile_indices(p) = (static_cast(i1(p) / tile_size) * ntx2 + + static_cast(i2(p) / tile_size)) * + ntx3 + + static_cast(i3(p) / tile_size); } else { raise::KernelError(HERE, "Wrong D in SortSpatially"); } + if constexpr (Count) { + Kokkos::atomic_add(&num_ppt(tile_indices(p)), 1); + } } } }; From 0dcda663804084342ad9792b42e377bcbd522c94 Mon Sep 17 00:00:00 2001 From: hayk Date: Thu, 26 Mar 2026 00:52:55 -0400 Subject: [PATCH 02/12] tile-based-sort --- src/framework/containers/particles_sort.cpp | 12 ++- src/global/utils/sorting.h | 86 ++++++++++++++------- 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/src/framework/containers/particles_sort.cpp b/src/framework/containers/particles_sort.cpp index 2fd0e6011..73d21bb6e 100644 --- a/src/framework/containers/particles_sort.cpp +++ b/src/framework/containers/particles_sort.cpp @@ -189,10 +189,14 @@ namespace ntt { array_t cell_indices { "cell_indices", npart() }; - Kokkos::parallel_for( - "FillCellIndices", - rangeActiveParticles(), - sort::PositionToCellIndex { i1, i2, i3, tag, cell_indices, nx2, nx3, total_cells }); + Kokkos::parallel_for("FillCellIndices", + rangeActiveParticles(), + sort::PositionToTileIndex { i1, + i2, + i3, + tag, + cell_indices, + grid.n_active() }); const auto slice = range_tuple_t(0, npart()); using sorter_op_t = Kokkos::BinOp1D; diff --git a/src/global/utils/sorting.h b/src/global/utils/sorting.h index c0639d81a..5c4be355e 100644 --- a/src/global/utils/sorting.h +++ b/src/global/utils/sorting.h @@ -4,7 +4,7 @@ * @implements * - sort::BinBool<> * - sort::BinTag<> - * - sort::PositionToCellIndex<> + * - sort::PositionToTileIndex<> * @namespaces: * - sort:: * @note BinBool sorts by boolean values "true" then "false" @@ -14,7 +14,6 @@ #ifndef GLOBAL_UTILS_SORTING_H #define GLOBAL_UTILS_SORTING_H -#include "enums.h" #include "global.h" #include "arch/kokkos_aliases.h" @@ -63,47 +62,80 @@ namespace sort { const int m_max_bins; }; - template - struct PositionToCellIndex { + template + struct PositionToTileIndex { const array_t i1, i2, i3; const array_t tag; - array_t cell_indices; - ncells_t nx2, nx3, total_cells; - - PositionToCellIndex(const array_t& i1, - const array_t& i2, - const array_t& i3, - const array_t& tag, - array_t& cell_indices, - ncells_t nx2, - ncells_t nx3, - ncells_t total_cells) + array_t tile_indices; + ncells_t tile_size; + array_t num_ppt; + + ncells_t ntx2, ntx3; + ncells_t total_tiles; + + PositionToTileIndex(const array_t& i1, + const array_t& i2, + const array_t& i3, + const array_t& tag, + array_t& tile_indices, + const std::vector ncells, + ncells_t tile_size = 1u, + array_t num_ppt = { "num_ppt", 0u }) : i1 { i1 } , i2 { i2 } , i3 { i3 } , tag { tag } - , cell_indices { cell_indices } - , nx2 { nx2 } - , nx3 { nx3 } - , total_cells { total_cells } {} + , tile_indices { tile_indices } + , tile_size { tile_size } + , num_ppt { num_ppt } { + raise::ErrorIf(ncells.size() >= static_cast(D), + "ncells size must match D", + HERE); + const auto ntx1 = static_cast(math::ceil( + static_cast(ncells[0]) / static_cast(tile_size))); + if constexpr (D == Dim::_1D) { + ntx2 = 1u; + ntx3 = 1u; + } else if constexpr (D == Dim::_2D) { + ntx2 = static_cast(math::ceil( + static_cast(ncells[1]) / static_cast(tile_size))); + ntx3 = 1u; + } else if constexpr (D == Dim::_3D) { + ntx2 = static_cast(math::ceil( + static_cast(ncells[1]) / static_cast(tile_size))); + ntx3 = static_cast(math::ceil( + static_cast(ncells[2]) / static_cast(tile_size))); + } else { + raise::Error("Wrong D in SortSpatially", HERE); + } + total_tiles = ntx1 * ntx2 * ntx3; + if constexpr (Count) { + raise::ErrorIf(num_ppt.extent(0) != total_tiles, + "num_ppt must have extent equal to total tiles", + HERE); + } + } Inline auto operator()(index_t p) const { if (tag(p) != ntt::ParticleTag::alive) { - cell_indices(p) = total_cells + 1u; + tile_indices(p) = total_tiles + 1u; } else { if constexpr (D == Dim::_1D) { - cell_indices(p) = static_cast(i1(p)); + tile_indices(p) = static_cast(i1(p)); } else if constexpr (D == Dim::_2D) { - cell_indices(p) = static_cast(i1(p)) * nx2 + - static_cast(i2(p)); + tile_indices(p) = static_cast(i1(p) / tile_size) * ntx2 + + static_cast(i2(p) / tile_size); } else if constexpr (D == Dim::_3D) { - cell_indices(p) = (static_cast(i1(p)) * nx2 + - static_cast(i2(p))) * - nx3 + - static_cast(i3(p)); + tile_indices(p) = (static_cast(i1(p) / tile_size) * ntx2 + + static_cast(i2(p) / tile_size)) * + ntx3 + + static_cast(i3(p) / tile_size); } else { raise::KernelError(HERE, "Wrong D in SortSpatially"); } + if constexpr (Count) { + Kokkos::atomic_add(&num_ppt(tile_indices(p)), 1); + } } } }; From 634f799d48f0d73afc449b069b1ed592dcbd942f Mon Sep 17 00:00:00 2001 From: hayk Date: Wed, 1 Apr 2026 19:57:52 -0400 Subject: [PATCH 03/12] minor (header to macro) --- src/framework/containers/particles.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/framework/containers/particles.h b/src/framework/containers/particles.h index c3ee1c1b5..6cc1fd6ba 100644 --- a/src/framework/containers/particles.h +++ b/src/framework/containers/particles.h @@ -18,7 +18,6 @@ #include "enums.h" #include "global.h" -#include "arch/directions.h" #include "arch/kokkos_aliases.h" #include "utils/error.h" #include "utils/formatting.h" @@ -27,6 +26,10 @@ #include "framework/domain/grid.h" #include "kernels/particle_pusher_sr.hpp" +#if defined(MPI_ENABLED) + #include "arch/directions.h" +#endif + #include #if defined(OUTPUT_ENABLED) From 02e51da31a87746c79ba2eaa66ebf644a71c57a0 Mon Sep 17 00:00:00 2001 From: hayk Date: Wed, 1 Apr 2026 19:58:13 -0400 Subject: [PATCH 04/12] new test for particle tiling --- src/global/tests/CMakeLists.txt | 1 + src/global/tests/sorting.cpp | 1 - src/global/tests/tiling.cpp | 314 ++++++++++++++++++++++++++++++++ 3 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 src/global/tests/tiling.cpp diff --git a/src/global/tests/CMakeLists.txt b/src/global/tests/CMakeLists.txt index c206f85b0..5b85d15f2 100644 --- a/src/global/tests/CMakeLists.txt +++ b/src/global/tests/CMakeLists.txt @@ -35,3 +35,4 @@ gen_test(comparators) gen_test(numeric) gen_test(param_container) gen_test(sorting) +gen_test(tiling) diff --git a/src/global/tests/sorting.cpp b/src/global/tests/sorting.cpp index 7e4b19b76..1dd4ecd9c 100644 --- a/src/global/tests/sorting.cpp +++ b/src/global/tests/sorting.cpp @@ -8,7 +8,6 @@ #include #include -#include #include auto main(int argc, char* argv[]) -> int { diff --git a/src/global/tests/tiling.cpp b/src/global/tests/tiling.cpp new file mode 100644 index 000000000..f9dc68198 --- /dev/null +++ b/src/global/tests/tiling.cpp @@ -0,0 +1,314 @@ +#include "arch/kokkos_aliases.h" +#include "utils/error.h" +#include "utils/numeric.h" +#include "utils/sorting.h" + +#include + +#include + +template +Inline void CheckValue(index_t, + const array_t&, + const array_t&, + const array_t&, + const array_t&, + const array_t&, + ncells_t, + ncells_t, + ncells_t, + ncells_t, + ncells_t); + +template <> +Inline void CheckValue(index_t p, + const array_t& i1, + const array_t&, + const array_t&, + const array_t& tag, + const array_t& tile_indices, + ncells_t nt1, + ncells_t, + ncells_t, + ncells_t ntiles, + ncells_t ts) { + if (tag(p) != ntt::ParticleTag::alive) { + if (tile_indices(p) != ntiles + 1u) { + raise::KernelError(HERE, "Dead particle assigned to wrong tile index"); + } + return; + } + const auto ti = static_cast(i1(p) / ts); + if (tile_indices(p) != ti) { + raise::KernelError(HERE, "Alive particle assigned to wrong tile index"); + } +} + +template <> +Inline void CheckValue(index_t p, + const array_t& i1, + const array_t& i2, + const array_t&, + const array_t& tag, + const array_t& tile_indices, + ncells_t nt1, + ncells_t nt2, + ncells_t, + ncells_t ntiles, + ncells_t ts) { + if (tag(p) != ntt::ParticleTag::alive) { + if (tile_indices(p) != ntiles + 1u) { + raise::KernelError(HERE, "Dead particle assigned to wrong tile index"); + } + return; + } + const auto ti = static_cast(i2(p) / ts) * nt1 + + static_cast(i1(p) / ts); + if (tile_indices(p) != ti) { + raise::KernelError(HERE, "Alive particle assigned to wrong tile index"); + } +} + +template <> +Inline void CheckValue(index_t p, + const array_t& i1, + const array_t& i2, + const array_t& i3, + const array_t& tag, + const array_t& tile_indices, + ncells_t nt1, + ncells_t nt2, + ncells_t nt3, + ncells_t ntiles, + ncells_t ts) { + if (tag(p) != ntt::ParticleTag::alive) { + if (tile_indices(p) != ntiles + 1u) { + raise::KernelError(HERE, "Dead particle assigned to wrong tile index"); + } + return; + } + const auto ti = (static_cast(i3(p) / ts) * nt2 + + static_cast(i2(p) / ts)) * + nt1 + + static_cast(i1(p) / ts); + if (tile_indices(p) != ti) { + raise::KernelError(HERE, "Alive particle assigned to wrong tile index"); + } +} + +template +void test_tiling(const array_t& i1, + const array_t& i2, + const array_t& i3, + const array_t& tag, + array_t& tile_indices, + npart_t npart, + const std::vector& ncells, + npart_t ndead) { + for (auto ts { 1u }; ts <= 11u; ++ts) { + ncells_t nt1 = 1u, nt2 = 1u, nt3 = 1u; + + nt1 = static_cast( + math::ceil(static_cast(ncells[0]) / static_cast(ts))); + if constexpr ((D == Dim::_2D) or (D == Dim::_3D)) { + nt2 = static_cast( + math::ceil(static_cast(ncells[1]) / static_cast(ts))); + } + if constexpr (D == Dim::_3D) { + nt3 = static_cast( + math::ceil(static_cast(ncells[2]) / static_cast(ts))); + } + + const auto ntiles = nt1 * nt2 * nt3; + + array_t num_ppt { "num_ppt", ntiles }; + Kokkos::parallel_for( + "Tiling", + npart, + sort::PositionToTileIndex { i1, i2, i3, tag, tile_indices, ncells, ts, num_ppt }); + Kokkos::parallel_for( + "Checking", + npart, + Lambda(index_t p) { + CheckValue(p, i1, i2, i3, tag, tile_indices, nt1, nt2, nt3, ntiles, ts); + }); + + npart_t tot_alive = 0u; + Kokkos::parallel_reduce( + "CountAliveInTiles", + ntiles, + Lambda(index_t t, npart_t & count) { count += num_ppt(t); }, + tot_alive); + raise::ErrorIf(tot_alive != npart - ndead, + "Error in counting particles per tile", + HERE); + } +} + +auto main(int argc, char* argv[]) -> int { + using namespace ntt; + Kokkos::initialize(argc, argv); + try { + { + const ncells_t nx1 = 123u, nx2 = 325u, nx3 = 111u; + const npart_t npart = 1234u; + + array_t i1 { "i1", npart }; + array_t i2 { "i2", npart }; + array_t i3 { "i3", npart }; + array_t tag { "tag", npart }; + + array_t tile_indices { "tile_indices", npart }; + + random_number_pool_t random_pool { constant::RandomSeed }; + + array_t ndead { "ndead" }; + + // test # 1 + Kokkos::parallel_for( + "Initialize", + npart, + Lambda(index_t p) { + auto gen = random_pool.get_state(); + i1(p) = gen.urand(0u, nx1); + i2(p) = gen.urand(0u, nx2); + i3(p) = gen.urand(0u, nx3); + tag(p) = (gen.drand() > 0.01) ? ParticleTag::alive : ParticleTag::dead; + random_pool.free_state(gen); + if (tag(p) == ParticleTag::dead) { + Kokkos::atomic_add(&ndead(), 1u); + } + }); + + auto ndead_h = Kokkos::create_mirror_view(ndead); + Kokkos::deep_copy(ndead_h, ndead); + + test_tiling(i1, i2, i3, tag, tile_indices, npart, { nx1 }, ndead_h()); + test_tiling(i1, i2, i3, tag, tile_indices, npart, { nx1, nx2 }, ndead_h()); + test_tiling(i1, + i2, + i3, + tag, + tile_indices, + npart, + { nx1, nx2, nx3 }, + ndead_h()); + } + + // test # 2 + { + const ncells_t nx1 = 23u, nx2 = 31u; + const npart_t npart = 4236u; + + array_t i1 { "i1", npart }; + array_t i2 { "i2", npart }; + array_t i3 { "i2" }; + array_t tag { "tag", npart }; + + for (auto tile_size { 6u }; tile_size <= 6u; ++tile_size) { + array_t tile_indices { "tile_indices", npart }; + const auto nt1 = static_cast( + math::ceil(static_cast(nx1) / static_cast(tile_size))); + const auto nt2 = static_cast( + math::ceil(static_cast(nx2) / static_cast(tile_size))); + const auto ntiles = nt1 * nt2; + const auto ncells = nx1 * nx2; + Kokkos::parallel_for( + "Initialize", + npart, + Lambda(index_t p) { + const auto cell_idx = p % ncells; + i1(p) = cell_idx % nx1; + i2(p) = cell_idx / nx1; + tag(p) = ParticleTag::alive; + }); + Kokkos::parallel_for("Tiling", + npart, + sort::PositionToTileIndex { + i1, + i2, + i3, + tag, + tile_indices, + std::vector { nx1, nx2 }, + tile_size + }); + Kokkos::parallel_for( + "CheckOutOfBounds", + npart, + Lambda(index_t p) { + const auto tile_idx = tile_indices(p); + const auto t1 = tile_idx % nt1; + const auto t2 = tile_idx / nt1; + const auto i1_min = t1 * tile_size; + const auto i1_max = math::min(i1_min + tile_size, nx1); + const auto i2_min = t2 * tile_size; + const auto i2_max = math::min(i2_min + tile_size, nx2); + if (i1(p) < i1_min or i1(p) >= i1_max or i2(p) < i2_min or + i2(p) >= i2_max) { + raise::KernelError(HERE, "Particle assigned to wrong tile index"); + } + }); + + // sort + using sorter_op_t = Kokkos::BinOp1D; + using sorter_t = Kokkos::BinSort; + auto bin_op = sorter_op_t { static_cast(ntiles + 1u), 0u, ntiles + 1u }; + auto sorter = sorter_t { tile_indices, bin_op, false }; + sorter.create_permute_vector(); + sorter.sort(i1); + sorter.sort(i2); + sorter.sort(tile_indices); + + auto i1_h = Kokkos::create_mirror_view(i1); + auto i2_h = Kokkos::create_mirror_view(i2); + auto ti_h = Kokkos::create_mirror_view(tile_indices); + Kokkos::deep_copy(i1_h, i1); + Kokkos::deep_copy(i2_h, i2); + Kokkos::deep_copy(ti_h, tile_indices); + + ncells_t current_tile = ti_h(0); + for (auto p { 0u }; p < npart; ++p) { + if (ti_h(p) != current_tile) { + if (ti_h(p) < current_tile) { + raise::Error("Tile indices not sorted correctly", HERE); + } + current_tile = ti_h(p); + } + const auto t1 = current_tile % nt1; + const auto t2 = current_tile / nt1; + const auto i1_min = t1 * tile_size; + const auto i1_max = math::min(i1_min + tile_size, nx1); + const auto i2_min = t2 * tile_size; + const auto i2_max = math::min(i2_min + tile_size, nx2); + if (i1_h(p) < i1_min or i1_h(p) >= i1_max or i2_h(p) < i2_min or + i2_h(p) >= i2_max) { + raise::Error("Particle assigned to wrong tile index after sorting", + HERE); + } + } + + // write to csv file + // std::fstream fout { "tiling_test_output.csv", std::fstream::out }; + // fout << "i1,i2,tile_index\n"; + // auto i1_h = Kokkos::create_mirror_view(i1); + // auto i2_h = Kokkos::create_mirror_view(i2); + // auto ti_h = Kokkos::create_mirror_view(tile_indices); + // Kokkos::deep_copy(i1_h, i1); + // Kokkos::deep_copy(i2_h, i2); + // Kokkos::deep_copy(ti_h, tile_indices); + // for (auto p { 0u }; p < npart; ++p) { + // fout << i1_h(p) << "," << i2_h(p) << "," << ti_h(p) << "\n"; + // } + // fout.close(); + } + } + + } catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + Kokkos::finalize(); + return 1; + } + Kokkos::finalize(); + return 0; +} From f9ebc0c9843663321475aba5b5c355b4e999c988 Mon Sep 17 00:00:00 2001 From: hayk Date: Wed, 1 Apr 2026 19:58:50 -0400 Subject: [PATCH 05/12] test for tiling & tile-based sorting --- src/global/utils/sorting.h | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/global/utils/sorting.h b/src/global/utils/sorting.h index 5c4be355e..838ed2ba3 100644 --- a/src/global/utils/sorting.h +++ b/src/global/utils/sorting.h @@ -70,7 +70,7 @@ namespace sort { ncells_t tile_size; array_t num_ppt; - ncells_t ntx2, ntx3; + ncells_t ntx1, ntx2; ncells_t total_tiles; PositionToTileIndex(const array_t& i1, @@ -88,25 +88,20 @@ namespace sort { , tile_indices { tile_indices } , tile_size { tile_size } , num_ppt { num_ppt } { - raise::ErrorIf(ncells.size() >= static_cast(D), + raise::ErrorIf(ncells.size() < static_cast(D), "ncells size must match D", HERE); - const auto ntx1 = static_cast(math::ceil( + ntx1 = static_cast(math::ceil( static_cast(ncells[0]) / static_cast(tile_size))); - if constexpr (D == Dim::_1D) { - ntx2 = 1u; - ntx3 = 1u; - } else if constexpr (D == Dim::_2D) { - ntx2 = static_cast(math::ceil( - static_cast(ncells[1]) / static_cast(tile_size))); - ntx3 = 1u; - } else if constexpr (D == Dim::_3D) { + ntx2 = 1u; + ncells_t ntx3 = 1u; + if constexpr ((D == Dim::_2D) or (D == Dim::_3D)) { ntx2 = static_cast(math::ceil( static_cast(ncells[1]) / static_cast(tile_size))); + } + if constexpr (D == Dim::_3D) { ntx3 = static_cast(math::ceil( static_cast(ncells[2]) / static_cast(tile_size))); - } else { - raise::Error("Wrong D in SortSpatially", HERE); } total_tiles = ntx1 * ntx2 * ntx3; if constexpr (Count) { @@ -121,15 +116,15 @@ namespace sort { tile_indices(p) = total_tiles + 1u; } else { if constexpr (D == Dim::_1D) { - tile_indices(p) = static_cast(i1(p)); + tile_indices(p) = static_cast(i1(p) / tile_size); } else if constexpr (D == Dim::_2D) { - tile_indices(p) = static_cast(i1(p) / tile_size) * ntx2 + - static_cast(i2(p) / tile_size); + tile_indices(p) = static_cast(i2(p) / tile_size) * ntx1 + + static_cast(i1(p) / tile_size); } else if constexpr (D == Dim::_3D) { - tile_indices(p) = (static_cast(i1(p) / tile_size) * ntx2 + + tile_indices(p) = (static_cast(i3(p) / tile_size) * ntx2 + static_cast(i2(p) / tile_size)) * - ntx3 + - static_cast(i3(p) / tile_size); + ntx1 + + static_cast(i1(p) / tile_size); } else { raise::KernelError(HERE, "Wrong D in SortSpatially"); } From e2e659a30a83c243f72250081318093d6712a8ee Mon Sep 17 00:00:00 2001 From: hayk Date: Wed, 1 Apr 2026 20:02:43 -0400 Subject: [PATCH 06/12] suppress unused namespace alias --- src/global/arch/kokkos_aliases.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/global/arch/kokkos_aliases.h b/src/global/arch/kokkos_aliases.h index f7b572181..7569e2234 100644 --- a/src/global/arch/kokkos_aliases.h +++ b/src/global/arch/kokkos_aliases.h @@ -255,7 +255,8 @@ auto CreateRangePolicyOnHost(const tuple_t&, const tuple_t&) -> range_h_t; // Random number pool/generator type alias -using random_number_pool_t = Kokkos::Random_XorShift64_Pool; +// (using math:: instead of Kokkos:: to suppress compiler warning on unused namespace alias) +using random_number_pool_t = math::Random_XorShift64_Pool; using random_generator_t = typename random_number_pool_t::generator_type; // Random number generator functions From 9f3c8237c01fdee067758caf60f2098129c4e015 Mon Sep 17 00:00:00 2001 From: haykh Date: Mon, 4 May 2026 09:11:03 -0400 Subject: [PATCH 07/12] 2bodyint --- src/archetypes/twobody_interactions.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/archetypes/twobody_interactions.h diff --git a/src/archetypes/twobody_interactions.h b/src/archetypes/twobody_interactions.h new file mode 100644 index 000000000..0c7ba2634 --- /dev/null +++ b/src/archetypes/twobody_interactions.h @@ -0,0 +1,20 @@ +#ifndef ARCHETYPES_TWO_BODY_INTERACTIONS_H +#define ARCHETYPES_TWO_BODY_INTERACTIONS_H + +#include "traits/metric.h" + +#include "framework/containers/particles.h" + +#include + +namespace arch { + + template + class TwoBodyComptonScattering { + // std::vector lepton_species_indices; + // std::vector photon_species_indices; + }; + +} // namespace arch + +#endif From 026b94d6c408056e14f1ef46e768099db6256557 Mon Sep 17 00:00:00 2001 From: haykh Date: Mon, 4 May 2026 11:28:34 -0400 Subject: [PATCH 08/12] bug in sorting --- src/framework/containers/particles_sort.cpp | 80 --------------------- src/global/utils/sorting.h | 55 +++++++------- tests/framework/particles_sort.cpp | 6 +- 3 files changed, 33 insertions(+), 108 deletions(-) diff --git a/src/framework/containers/particles_sort.cpp b/src/framework/containers/particles_sort.cpp index a29cfba86..2fd94628b 100644 --- a/src/framework/containers/particles_sort.cpp +++ b/src/framework/containers/particles_sort.cpp @@ -258,83 +258,3 @@ namespace ntt { #undef PARTICLES_SORT } // namespace ntt - -// template -// void AllocateArrayOnGrid(nddata_t& arr, -// const Grid& grid, -// const std::string& name) { -// if constexpr (D == Dim::_1D) { -// arr = nddata_t { name, grid.n_active(in::x1) }; -// } else if constexpr (D == Dim::_2D) { -// arr = nddata_t { name, grid.n_active(in::x1), grid.n_active(in::x2) }; -// } else if constexpr (D == Dim::_3D) { -// arr = nddata_t { name, -// grid.n_active(in::x1), -// grid.n_active(in::x2), -// grid.n_active(in::x3) }; -// } else { -// raise::Error("Unsupported dimension for array allocation", HERE); -// } -// } -// -// -// array_t cell_idx { "cell_indices", npart() }; -// const auto num_cells = grid.num_active(); -// -// nddata_t num_ppc; -// nddata_t disp_map; -// AllocateArrayOnGrid(num_ppc, grid, "num_ppc"); -// AllocateArrayOnGrid(disp_map, grid, "disp_map"); -// auto num_ppc_scatter = -// Kokkos::Experimental::create_scatter_view(num_ppc); Kokkos::parallel_for( -// "ComputeNumPPC", -// rangeActiveParticles(), -// Lambda(index_t p) { -// if (tag_p(p) != ParticleTag::alive) { -// return; -// } -// auto num_ppc_acc = num_ppc_scatter.access(); -// if constexpr (D == Dim::_1D) { -// num_ppc_acc(i1_p(p)) += 1u; -// } else if constexpr (D == Dim::_2D) { -// num_ppc_acc(i1_p(p), i2_p(p)) += 1u; -// } else { -// num_ppc_acc(i1_p(p), i2_p(p), i3_p(p)) += 1u; -// } -// }); -// Kokkos::Experimental::contribute(num_ppc, num_ppc_scatter); -// -// npart_t total_sum = 0u; -// Kokkos::parallel_scan( -// "ComputeDisplacementMap", -// total_cells, -// Lambda(index_t cell, npart_t & cumulative_sum, bool is_final) { -// ncells_t i1, i2, i3; -// if constexpr (D == Dim::_1D) { -// i1 = cell; -// } else if constexpr (D == Dim::_2D) { -// i1 = cell / nx2; -// i2 = cell % nx2; -// } else { -// i1 = cell / (nx2 * nx3); -// i2 = (cell % (nx2 * nx3)) / nx3; -// i3 = cell % nx3; -// } -// if (is_final) { -// if constexpr (D == Dim::_1D) { -// disp_map(i1) = cumulative_sum; -// } else if constexpr (D == Dim::_2D) { -// disp_map(i1, i2) = cumulative_sum; -// } else { -// disp_map(i1, i2, i3) = cumulative_sum; -// } -// } -// if constexpr (D == Dim::_1D) { -// cumulative_sum += num_ppc(i1); -// } else if constexpr (D == Dim::_2D) { -// cumulative_sum += num_ppc(i1, i2); -// } else { -// cumulative_sum += num_ppc(i1, i2, i3); -// } -// }, -// total_sum); diff --git a/src/global/utils/sorting.h b/src/global/utils/sorting.h index 838ed2ba3..e1db97bde 100644 --- a/src/global/utils/sorting.h +++ b/src/global/utils/sorting.h @@ -1,6 +1,6 @@ /** * @file utils/sorting.h - * @brief Comparator structs for Kokkos bin-sorting + * @brief Defines sorting functors for particle sorting * @implements * - sort::BinBool<> * - sort::BinTag<> @@ -70,40 +70,45 @@ namespace sort { ncells_t tile_size; array_t num_ppt; - ncells_t ntx1, ntx2; - ncells_t total_tiles; - - PositionToTileIndex(const array_t& i1, - const array_t& i2, - const array_t& i3, - const array_t& tag, - array_t& tile_indices, - const std::vector ncells, - ncells_t tile_size = 1u, - array_t num_ppt = { "num_ppt", 0u }) + ncells_t ntx2 { 0u }, ntx3 { 0u }; + ncells_t total_tiles { 0u }; + + PositionToTileIndex(const array_t& i1, + const array_t& i2, + const array_t& i3, + const array_t& tag, + array_t& tile_indices, + const std::vector& ncells, + ncells_t tile_size = 1u, + const array_t& num_ppt = { "num_ppt", 0u }) : i1 { i1 } , i2 { i2 } , i3 { i3 } , tag { tag } , tile_indices { tile_indices } , tile_size { tile_size } - , num_ppt { num_ppt } { + , num_ppt { num_ppt } + , ntx2 { 1u } + , ntx3 { 1u } + , total_tiles { 1u } { raise::ErrorIf(ncells.size() < static_cast(D), "ncells size must match D", HERE); - ntx1 = static_cast(math::ceil( - static_cast(ncells[0]) / static_cast(tile_size))); - ntx2 = 1u; - ncells_t ntx3 = 1u; + if constexpr ((D == Dim::_1D) or (D == Dim::_2D) or (D == Dim::_3D)) { + npart_t ntx1 = static_cast(math::ceil( + static_cast(ncells[0]) / static_cast(tile_size))); + total_tiles *= ntx1; + } if constexpr ((D == Dim::_2D) or (D == Dim::_3D)) { - ntx2 = static_cast(math::ceil( + ntx2 = static_cast(math::ceil( static_cast(ncells[1]) / static_cast(tile_size))); + total_tiles *= ntx2; } if constexpr (D == Dim::_3D) { - ntx3 = static_cast(math::ceil( + ntx3 = static_cast(math::ceil( static_cast(ncells[2]) / static_cast(tile_size))); + total_tiles *= ntx3; } - total_tiles = ntx1 * ntx2 * ntx3; if constexpr (Count) { raise::ErrorIf(num_ppt.extent(0) != total_tiles, "num_ppt must have extent equal to total tiles", @@ -118,13 +123,13 @@ namespace sort { if constexpr (D == Dim::_1D) { tile_indices(p) = static_cast(i1(p) / tile_size); } else if constexpr (D == Dim::_2D) { - tile_indices(p) = static_cast(i2(p) / tile_size) * ntx1 + - static_cast(i1(p) / tile_size); + tile_indices(p) = static_cast(i1(p) / tile_size) * ntx2 + + static_cast(i2(p) / tile_size); } else if constexpr (D == Dim::_3D) { - tile_indices(p) = (static_cast(i3(p) / tile_size) * ntx2 + + tile_indices(p) = (static_cast(i1(p) / tile_size) * ntx2 + static_cast(i2(p) / tile_size)) * - ntx1 + - static_cast(i1(p) / tile_size); + ntx3 + + static_cast(i3(p) / tile_size); } else { raise::KernelError(HERE, "Wrong D in SortSpatially"); } diff --git a/tests/framework/particles_sort.cpp b/tests/framework/particles_sort.cpp index a25bff89a..a65131706 100644 --- a/tests/framework/particles_sort.cpp +++ b/tests/framework/particles_sort.cpp @@ -61,8 +61,8 @@ auto main(int argc, char* argv[]) -> int { i2_p(p) = 23u; weight_p(p) = 3.0; } - pld_r(p, 0) = weight_p(p) + 0.5; - pld_r(p, 1) = weight_p(p) + 10.5; + pld_r(p, 0) = weight_p(p) + static_cast(0.5); + pld_r(p, 1) = weight_p(p) + static_cast(10.5); pld_i(p, 0) = static_cast(weight_p(p) + 10.0); } else { tag_p(p) = ntt::ParticleTag::dead; @@ -196,7 +196,7 @@ auto main(int argc, char* argv[]) -> int { } } catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; + std::cerr << "Error: " << e.what() << '\n'; ntt::GlobalFinalize(); return 1; } From 670c16e1a61a993565c13cbfcb33313513c011f9 Mon Sep 17 00:00:00 2001 From: haykh Date: Mon, 4 May 2026 13:53:06 -0400 Subject: [PATCH 09/12] pusherarrays -> particlearrays + fixes in tests --- .../examples/custom_particle_update/pgen.hpp | 8 +- pgens/examples/piston/pgen.hpp | 6 +- src/archetypes/piston.h | 38 ++-- src/archetypes/twobody_interactions.h | 212 ++++++++++++++++-- src/engines/grpic/particle_pusher.h | 8 +- src/engines/srpic/particle_pusher.h | 4 +- src/framework/containers/particles.cpp | 28 +-- src/framework/containers/particles.h | 53 ++--- src/global/traits/policies.h | 5 +- src/kernels/pushers/context.h | 58 +---- src/kernels/pushers/gr.hpp | 5 +- src/kernels/pushers/sr.hpp | 5 +- tests/framework/checkpoint-data.cpp | 124 +++++----- tests/framework/checkpoint-extents.cpp | 68 +++--- tests/framework/particles_sort.cpp | 12 +- tests/global/tiling.cpp | 48 ++-- tests/global/traits_policies.cpp | 5 +- tests/kernels/custom_emission.cpp | 14 +- tests/kernels/custom_prtl_update.cpp | 52 +++-- tests/kernels/ext_force.cpp | 24 +- tests/kernels/gca_pusher.cpp | 25 ++- tests/kernels/prtl_bc.cpp | 22 +- tests/kernels/pusher.cpp | 25 +-- 23 files changed, 487 insertions(+), 362 deletions(-) diff --git a/pgens/examples/custom_particle_update/pgen.hpp b/pgens/examples/custom_particle_update/pgen.hpp index 3d95eaeca..067dcdd4d 100644 --- a/pgens/examples/custom_particle_update/pgen.hpp +++ b/pgens/examples/custom_particle_update/pgen.hpp @@ -8,8 +8,10 @@ #include "archetypes/energy_dist.h" #include "archetypes/particle_injector.h" +#include "framework/containers/particles.h" #include "framework/domain/domain.h" #include "framework/domain/metadomain.h" +#include "kernels/pushers/context.h" #include @@ -137,8 +139,8 @@ namespace user { Inline void operator()(index_t p, const kernel::sr::PusherContext& ctx, const kernel::sr::PusherBoundaries&, - const kernel::PusherArrays& particles, - const M& metric) const { + const ntt::ParticleArrays& particles, + const M& metric) const { const auto x_Cd = static_cast(particles.i1(p)) + static_cast(particles.dx1(p)); @@ -242,4 +244,4 @@ namespace user { #undef from_Xi_to_i #undef i_di_to_Xi -#endif // PROBLEM_GENERATOR_H \ No newline at end of file +#endif // PROBLEM_GENERATOR_H diff --git a/pgens/examples/piston/pgen.hpp b/pgens/examples/piston/pgen.hpp index fe8fb6d4b..bcabfaa03 100644 --- a/pgens/examples/piston/pgen.hpp +++ b/pgens/examples/piston/pgen.hpp @@ -10,9 +10,11 @@ #include "archetypes/energy_dist.h" #include "archetypes/particle_injector.h" #include "archetypes/piston.h" +#include "framework/containers/particles.h" #include "framework/domain/domain.h" #include "framework/domain/metadomain.h" #include "framework/parameters/parameters.h" +#include "kernels/pushers/context.h" namespace user { using namespace ntt; @@ -80,8 +82,8 @@ namespace user { Inline void operator()(index_t p, const kernel::sr::PusherContext& ctx, const kernel::sr::PusherBoundaries&, - const kernel::PusherArrays& particles, - const M& metric) const { + const ParticleArrays& particles, + const M& metric) const { real_t piston_pos; if (x_piston > global_xmax) { diff --git a/src/archetypes/piston.h b/src/archetypes/piston.h index f31dbdffa..57d7becbb 100644 --- a/src/archetypes/piston.h +++ b/src/archetypes/piston.h @@ -15,7 +15,7 @@ #include "traits/metric.h" -#include "kernels/pushers/context.h" +#include "framework/containers/particles.h" /* -------------------------------------------------------------------------- */ /* Local macros (same as in particle_pusher_sr.hpp) */ @@ -49,13 +49,13 @@ namespace arch { * @param is_left Is piston on the left side of the box or right side of the box */ template - Inline bool CrossesPiston(index_t p, - real_t dt, - const kernel::PusherArrays& particles, - const M& metric, - real_t piston_position, - real_t piston_v, - bool is_left) { + Inline bool CrossesPiston(index_t p, + real_t dt, + const ntt::ParticleArrays& particles, + const M& metric, + real_t piston_position, + real_t piston_v, + bool is_left) { const real_t x1_Cd = i_di_to_Xi(particles.i1(p), particles.dx1(p)); // x1_Cd_wallmove is not the actual particle coordinate // it is particle position minus how much the wall has moved in this @@ -82,13 +82,13 @@ namespace arch { * @param massive Whether the particle is massive or massless (e.g. photon) */ template - Inline void Piston(index_t p, - real_t dt, - const kernel::PusherArrays& particles, - const M& metric, - real_t piston_position, - real_t piston_v, - bool massive) { + Inline void Piston(index_t p, + real_t dt, + const ntt::ParticleArrays& particles, + const M& metric, + real_t piston_position, + real_t piston_v, + bool massive) { // check if particle actually crosses the piston, if not return if (!CrossesPiston(p, dt, particles, metric, piston_position, piston_v, true)) { @@ -142,8 +142,8 @@ namespace arch { piston_v) * dt_to_piston; - i_w_coll += static_cast(dx_w_coll >= ONE) - - static_cast(dx_w_coll < ZERO); + i_w_coll += static_cast(dx_w_coll >= ONE) - + static_cast(dx_w_coll < ZERO); dx_w_coll -= static_cast(dx_w_coll >= ONE); dx_w_coll += static_cast(dx_w_coll < ZERO); @@ -153,8 +153,8 @@ namespace arch { remaining_dt_inv_energy + dx_w_coll; - particles.i1(p) += static_cast(particles.dx1(p) >= ONE) - - static_cast(particles.dx1(p) < ZERO); + particles.i1(p) += static_cast(particles.dx1(p) >= ONE) - + static_cast(particles.dx1(p) < ZERO); particles.dx1(p) -= static_cast(particles.dx1(p) >= ONE); particles.dx1(p) += static_cast(particles.dx1(p) < ZERO); } diff --git a/src/archetypes/twobody_interactions.h b/src/archetypes/twobody_interactions.h index 0c7ba2634..8e26e7cbe 100644 --- a/src/archetypes/twobody_interactions.h +++ b/src/archetypes/twobody_interactions.h @@ -1,20 +1,192 @@ -#ifndef ARCHETYPES_TWO_BODY_INTERACTIONS_H -#define ARCHETYPES_TWO_BODY_INTERACTIONS_H - -#include "traits/metric.h" - -#include "framework/containers/particles.h" - -#include - -namespace arch { - - template - class TwoBodyComptonScattering { - // std::vector lepton_species_indices; - // std::vector photon_species_indices; - }; - -} // namespace arch - -#endif +// #ifndef ARCHETYPES_TWO_BODY_INTERACTIONS_H +// #define ARCHETYPES_TWO_BODY_INTERACTIONS_H +// +// #include "traits/metric.h" +// +// #include "framework/containers/particles.h" +// +// #include +// #include +// +// #include +// #include +// #include +// +// #include "utils.h" +// +// namespace arch { +// +// struct CollisionSpecies { +// const spidx_t sp; +// const npart_t npart; +// const ncells_t num_tiles; +// +// const array_t tileidx; +// const array_t num_ppt; +// +// CollisionSpecies(spidx_t sp, +// npart_t npart, +// const array_t& tileidx, +// const array_t& num_ppt) +// : sp { sp } +// , npart { npart } +// , num_tiles { static_cast(num_ppt.extent(0)) } +// , tileidx { tileidx } +// , num_ppt { num_ppt } {} +// }; +// +// struct CollisionGroup { +// std::vector group; +// +// array_t combined_idx; +// array_t combined_tileidx; +// array_t combined_num_ppt; +// array_t tile_offsets; +// +// ncells_t num_tiles { 0u }; +// +// [[nodiscard]] +// auto total_npart() -> npart_t { +// npart_t total_npart = 0u; +// for (const auto& species : group) { +// total_npart += species.npart; +// } +// return total_npart; +// } +// +// CollisionGroup(const std::vector& particles, +// const Domain& domain, +// ncells_t tile_size, +// random_pool_t& random_pool) { +// for (const auto& species : particles) { +// auto tile_indexing = PositionToTileIndex(species.i1, +// species.i2, +// species.get_npart(), +// domain.nx1, +// domain.nx2, +// tile_size); +// Kokkos::parallel_for("TileIndexing", species.get_npart(), tile_indexing); +// group.emplace_back(species.sp, +// species.get_npart(), +// tile_indexing.tile_indices, +// tile_indexing.num_ppt); +// if (num_tiles == 0u) { +// num_tiles = group.back().num_tiles; +// } else if (num_tiles != group.back().num_tiles) { +// throw std::runtime_error { "unequal num_tiles" }; +// } +// if (group.back().tileidx.extent(0) != species.get_npart()) { +// throw std::runtime_error { "tileidx must have the same extent as " +// "npart for all species in group" }; +// } +// } +// +// const auto tot_npart = total_npart(); +// combined_idx = array_t { "combined_idx", tot_npart }; +// combined_tileidx = array_t { "combined_tileidx", tot_npart }; +// combined_num_ppt = array_t { "combined_num_ppt", num_tiles }; +// tile_offsets = array_t { "tile_offsets", num_tiles }; +// +// { +// // combine particle indices in the group & compute total number in each tile +// npart_t offset = 0u; +// for (const auto& species : group) { +// Kokkos::parallel_for( +// "CombineInGroup", +// species.npart, +// ClassLambda(const npart_t p) { +// // pack species idx into top 8 bits + prtl index into the remaining 56 bits +// combined_idx(offset + p) = (static_cast(species.sp) << 56) | +// static_cast(p); +// combined_tileidx(offset + p) = species.tileidx(p); +// }); +// offset += species.npart; +// Kokkos::parallel_for( +// "CombineNumPpt", +// species.num_tiles, +// ClassLambda(const ncells_t t) { +// combined_num_ppt(t) += species.num_ppt(t); +// }); +// Kokkos::fence(); +// } +// } +// { +// // randomly shuffle particles within each tile and sort by tiles +// array_t shuffle_key { "shuffle_key", tot_npart }; +// Kokkos::parallel_for( +// "PackRandom", +// tot_npart, +// ClassLambda(const npart_t p) { +// auto gen = random_pool.get_state(); +// const auto rnd = static_cast(gen.urand()); +// random_pool.free_state(gen); +// const auto tile_idx = static_cast(combined_tileidx(p)); +// // packing top 32 bits with tile index, and the rest -- random +// shuffle_key(p) = (tile_idx << 32) | rnd; +// }); +// Kokkos::Experimental::sort_by_key(Kokkos::DefaultExecutionSpace {}, +// shuffle_key, +// combined_idx); +// } +// { +// // compute index offsets for each tile +// Kokkos::parallel_scan( +// "TileOffsets", +// num_tiles, +// ClassLambda(const ncells_t t, npart_t& acc, const bool final) { +// if (final) { +// tile_offsets(t) = acc; +// } +// acc += combined_num_ppt(t); +// }); +// } +// } +// }; +// +// template +// void TwoBodyInteraction(const std::vector& species1, +// const std::vector& species2, +// const Domain& domain, +// ncells_t tile_size, +// random_pool_t& random_pool, +// const C& collision_policy) { +// const auto group1 = CollisionGroup(species1, domain, tile_size, random_pool); +// const auto group2 = CollisionGroup(species2, domain, tile_size, random_pool); +// if (group1.num_tiles != group2.num_tiles) { +// throw std::runtime_error("number of tiles differ in group1 vs group2"); +// } +// const auto num_tiles = group1.num_tiles; +// +// const auto& combined_idx1 = group1.combined_idx; +// const auto& combined_idx2 = group2.combined_idx; +// const auto& combined_num_ppt1 = group1.combined_num_ppt; +// const auto& combined_num_ppt2 = group2.combined_num_ppt; +// const auto& tile_offsets1 = group1.tile_offsets; +// const auto& tile_offsets2 = group2.tile_offsets; +// +// Kokkos::parallel_for( +// "EmitPairs", +// Kokkos::TeamPolicy<>(num_tiles, Kokkos::AUTO), +// Lambda(const Kokkos::TeamPolicy<>::member_type& team) { +// const auto t = team.league_rank(); +// const auto k = Kokkos::min(combined_num_ppt1(t), combined_num_ppt2(t)); +// const auto o1 = tile_offsets1(t); +// const auto o2 = tile_offsets2(t); +// Kokkos::parallel_for(Kokkos::TeamThreadRange(team, k), [&](const npart_t i) { +// // unpack the higher 8 bits +// const auto sp1 = static_cast(combined_idx1(o1 + i) >> 56); +// const auto sp2 = static_cast(combined_idx2(o2 + i) >> 56); +// +// // unpack the lower 56 bits +// const auto p1 = static_cast(combined_idx1(o1 + i) & +// ((1ull << 56) - 1)); +// const auto p2 = static_cast(combined_idx2(o2 + i) & +// ((1ull << 56) - 1)); +// collision_policy(sp1, p1, sp2, p2); +// }); +// }); +// } +// +// } // namespace arch +// +// #endif diff --git a/src/engines/grpic/particle_pusher.h b/src/engines/grpic/particle_pusher.h index bfcec8089..ebcfe2912 100644 --- a/src/engines/grpic/particle_pusher.h +++ b/src/engines/grpic/particle_pusher.h @@ -54,7 +54,7 @@ namespace ntt { const auto pusher_boundaries = kernel::gr::PusherBoundaries { domain.mesh.prtl_bc() }; - auto pusher_arrays = species.PusherKernelArrays(); + // auto pusher_arrays = species.PusherKernelArrays(); if (species.pusher() == ParticlePusher::PHOTON) { const auto range_policy = @@ -65,7 +65,7 @@ namespace ntt { range_policy, kernel::gr::Pusher_kernel(pusher_ctx, pusher_boundaries, - pusher_arrays, + species, domain.fields.em, domain.fields.em0, domain.mesh.metric)); @@ -78,7 +78,7 @@ namespace ntt { range_policy, kernel::gr::Pusher_kernel(pusher_ctx, pusher_boundaries, - pusher_arrays, + species, domain.fields.em, domain.fields.em0, domain.mesh.metric)); @@ -91,4 +91,4 @@ namespace ntt { } // namespace grpic } // namespace ntt -#endif // ENGINES_GRPIC_PARTICLE_PUSHER_H \ No newline at end of file +#endif // ENGINES_GRPIC_PARTICLE_PUSHER_H diff --git a/src/engines/srpic/particle_pusher.h b/src/engines/srpic/particle_pusher.h index 42b26780f..d708cfb6b 100644 --- a/src/engines/srpic/particle_pusher.h +++ b/src/engines/srpic/particle_pusher.h @@ -138,8 +138,6 @@ namespace ntt { domain.mesh.prtl_bc() }; - auto pusher_arrays = species.PusherKernelArrays(); - kernel::sr::MakePusherPolicy( @@ -156,7 +154,7 @@ namespace ntt { species.rangeActiveParticles(), kernel::sr::Pusher_kernel { pusher_ctx, pusher_boundaries, - pusher_arrays, + species, domain.fields.em, domain.mesh.metric, policies }); diff --git a/src/framework/containers/particles.cpp b/src/framework/containers/particles.cpp index aaaede0e2..f1e67acdd 100644 --- a/src/framework/containers/particles.cpp +++ b/src/framework/containers/particles.cpp @@ -6,7 +6,6 @@ #include "arch/kokkos_aliases.h" #include "framework/containers/species.h" -#include "kernels/pushers/context.h" #include #include @@ -30,7 +29,8 @@ namespace ntt { EmissionTypeFlag emission_policy_flag, unsigned short npld_r, unsigned short npld_i) - : ParticleSpecies { index, + : ParticleArrays { index } + , ParticleSpecies { index, label, m, ch, @@ -85,30 +85,6 @@ namespace ntt { } } - template - auto Particles::PusherKernelArrays() -> kernel::PusherArrays { - kernel::PusherArrays pusher_arrays { index() }; - pusher_arrays.i1 = i1; - pusher_arrays.i2 = i2; - pusher_arrays.i3 = i3; - pusher_arrays.i1_prev = i1_prev; - pusher_arrays.i2_prev = i2_prev; - pusher_arrays.i3_prev = i3_prev; - pusher_arrays.dx1 = dx1; - pusher_arrays.dx2 = dx2; - pusher_arrays.dx3 = dx3; - pusher_arrays.dx1_prev = dx1_prev; - pusher_arrays.dx2_prev = dx2_prev; - pusher_arrays.dx3_prev = dx3_prev; - pusher_arrays.ux1 = ux1; - pusher_arrays.ux2 = ux2; - pusher_arrays.ux3 = ux3; - pusher_arrays.phi = phi; - pusher_arrays.weight = weight; - pusher_arrays.tag = tag; - return pusher_arrays; - } - template struct Particles; template struct Particles; template struct Particles; diff --git a/src/framework/containers/particles.h b/src/framework/containers/particles.h index 3a3e1b802..2f0a88856 100644 --- a/src/framework/containers/particles.h +++ b/src/framework/containers/particles.h @@ -2,7 +2,8 @@ * @file framework/containers/particles.h * @brief Definition of the particle container class * @implements - * - ntt::Particles<> : ntt::ParticleSpecies + * - ntt::ParticleArrays + * - ntt::Particles<> : ntt::ParticleSpecies, ntt::ParticleArrays * @cpp: * - particles.cpp * - particles_io.cpp @@ -27,7 +28,6 @@ #include "framework/containers/species.h" #include "framework/domain/grid.h" -#include "kernels/pushers/context.h" #if defined(MPI_ENABLED) #include "arch/directions.h" @@ -44,26 +44,11 @@ namespace ntt { - /** - * @brief Container class to carry particle information for a specific species - * @tparam D The dimension of the simulation - * @tparam S The simulation engine being used - */ - template - struct Particles : public ParticleSpecies { - private: - // Number of currently active (used) particles - npart_t m_npart { 0 }; - npart_t m_counter { 0 }; - bool m_is_sorted { false }; + struct ParticleArrays { + const spidx_t sp; -#if !defined(MPI_ENABLED) - const std::size_t m_ntags { 2 }; -#else // MPI_ENABLED - const std::size_t m_ntags { (std::size_t)(2 + math::pow(3, (int)D) - 1) }; -#endif + ParticleArrays(spidx_t sp = 0u) : sp { sp } {} - public: // Cell indices of the current particle array_t i1, i2, i3; // Displacement of a particle within the cell @@ -83,7 +68,29 @@ namespace ntt { array_t pld_i; // phi coordinate (for axisymmetry) array_t phi; + }; + + /** + * @brief Container class to carry particle information for a specific species + * @tparam D The dimension of the simulation + * @tparam S The simulation engine being used + */ + template + struct Particles : public ParticleSpecies, + public ParticleArrays { + private: + // Number of currently active (used) particles + npart_t m_npart { 0 }; + npart_t m_counter { 0 }; + bool m_is_sorted { false }; +#if !defined(MPI_ENABLED) + const std::size_t m_ntags { 2 }; +#else // MPI_ENABLED + const std::size_t m_ntags { (std::size_t)(2 + math::pow(3, (int)D) - 1) }; +#endif + + public: // for empty allocation Particles() {} @@ -277,12 +284,6 @@ namespace ntt { */ void SyncHostDevice(); - /** - * @brief Get the arrays required for the particle pusher kernel - * @returns The struct of arrays for the particle pusher kernel - */ - auto PusherKernelArrays() -> kernel::PusherArrays; - #if defined(MPI_ENABLED) /** * @brief Communicate particles across neighboring meshblocks diff --git a/src/global/traits/policies.h b/src/global/traits/policies.h index 27374c4e3..fae45b685 100644 --- a/src/global/traits/policies.h +++ b/src/global/traits/policies.h @@ -29,6 +29,7 @@ #include "traits/archetypes.h" +#include "framework/containers/particles.h" #include "kernels/pushers/context.h" #include @@ -129,7 +130,7 @@ concept CustomParticleUpdatePolicyClass = index_t p, const kernel::sr::PusherContext& pusher_ctx, const kernel::sr::PusherBoundaries& pusher_boundaries, - const kernel::PusherArrays& particles, + const ntt::ParticleArrays& particles, const M& metric) { { cpu(p, pusher_ctx, pusher_boundaries, particles, metric) @@ -137,4 +138,4 @@ concept CustomParticleUpdatePolicyClass = } or traits::custom_prtl_update::IsNoPolicy; -#endif // TRAITS_POLICIES_H \ No newline at end of file +#endif // TRAITS_POLICIES_H diff --git a/src/kernels/pushers/context.h b/src/kernels/pushers/context.h index 4f4fbd717..219e79e81 100644 --- a/src/kernels/pushers/context.h +++ b/src/kernels/pushers/context.h @@ -10,7 +10,6 @@ * - kernel::sr::PusherBoundaries<> * - kernel::gr::PusherContext * - kernel::gr::PusherBoundaries<> - * - kernel::PusherArrays * @namespaces: * - kernel:: */ @@ -229,61 +228,6 @@ namespace kernel { }; } // namespace gr - struct PusherArrays { - array_t i1, i2, i3; - array_t i1_prev, i2_prev, i3_prev; - array_t dx1, dx2, dx3; - array_t dx1_prev, dx2_prev, dx3_prev; - array_t ux1, ux2, ux3; - array_t phi; - array_t weight; - array_t tag; - - PusherArrays(spidx_t sp) : sp { sp } {} - - PusherArrays(spidx_t sp, - array_t& i1, - array_t& i2, - array_t& i3, - array_t& i1_prev, - array_t& i2_prev, - array_t& i3_prev, - array_t& dx1, - array_t& dx2, - array_t& dx3, - array_t& dx1_prev, - array_t& dx2_prev, - array_t& dx3_prev, - array_t& ux1, - array_t& ux2, - array_t& ux3, - array_t& phi, - array_t& weight, - array_t& tag) - : sp { sp } - , i1 { i1 } - , i2 { i2 } - , i3 { i3 } - , i1_prev { i1_prev } - , i2_prev { i2_prev } - , i3_prev { i3_prev } - , dx1 { dx1 } - , dx2 { dx2 } - , dx3 { dx3 } - , dx1_prev { dx1_prev } - , dx2_prev { dx2_prev } - , dx3_prev { dx3_prev } - , ux1 { ux1 } - , ux2 { ux2 } - , ux3 { ux3 } - , phi { phi } - , weight { weight } - , tag { tag } {} - - private: - spidx_t sp; - }; - } // namespace kernel -#endif // KERNELS_PUSHERS_CONTEXT_H \ No newline at end of file +#endif // KERNELS_PUSHERS_CONTEXT_H diff --git a/src/kernels/pushers/gr.hpp b/src/kernels/pushers/gr.hpp index 27d215436..1dddaa40b 100644 --- a/src/kernels/pushers/gr.hpp +++ b/src/kernels/pushers/gr.hpp @@ -21,6 +21,7 @@ #include "utils/error.h" #include "utils/numeric.h" +#include "framework/containers/particles.h" #include "kernels/particle_shapes.hpp" #include "kernels/pushers/context.h" @@ -74,7 +75,7 @@ namespace kernel::gr { private: const PusherContext ctx; const PusherBoundaries bc; - PusherArrays particles; + ParticleArrays particles; const randacc_ndfield_t DB; const randacc_ndfield_t DB0; @@ -88,7 +89,7 @@ namespace kernel::gr { public: Pusher_kernel(const PusherContext& pusher_ctx, const PusherBoundaries& pusher_boundaries, - PusherArrays& pusher_arrays, + ParticleArrays& pusher_arrays, const ndfield_t& DB, const ndfield_t& DB0, const M& metric) diff --git a/src/kernels/pushers/sr.hpp b/src/kernels/pushers/sr.hpp index ecea4d027..08188fb3c 100644 --- a/src/kernels/pushers/sr.hpp +++ b/src/kernels/pushers/sr.hpp @@ -26,6 +26,7 @@ #include "utils/error.h" #include "utils/numeric.h" +#include "framework/containers/particles.h" #include "kernels/particle_shapes.hpp" #include "kernels/pushers/context.h" #include "kernels/pushers/sr_policies.h" @@ -86,7 +87,7 @@ namespace kernel::sr { const PusherContext ctx; const PusherBoundaries bc; - PusherArrays particles; + ParticleArrays particles; const randacc_ndfield_t EB; @@ -97,7 +98,7 @@ namespace kernel::sr { Pusher_kernel(const PusherContext& pusher_ctx, const PusherBoundaries& pusher_boundaries, - PusherArrays& pusher_arrays, + ParticleArrays& pusher_arrays, const randacc_ndfield_t& EB, const M& metric, const P& policies = {}) diff --git a/tests/framework/checkpoint-data.cpp b/tests/framework/checkpoint-data.cpp index 3099593de..669e0a381 100644 --- a/tests/framework/checkpoint-data.cpp +++ b/tests/framework/checkpoint-data.cpp @@ -16,11 +16,11 @@ #include "utils/error.h" #include "utils/formatting.h" +#include "metrics/minkowski.h" + #include "framework/domain/metadomain.h" #include "framework/parameters/parameters.h" -#include "metrics/minkowski.h" - #include #include #include @@ -50,30 +50,34 @@ auto main(int argc, char* argv[]) -> int { using M = Minkowski; const std::vector res { 64 }; - const boundaries_t init_extent { { static_cast(0.0), - static_cast(10.0) } }; - const boundaries_t fldsbc { { FldsBC::PERIODIC, FldsBC::PERIODIC } }; - const boundaries_t prtlbc { { PrtlBC::PERIODIC, PrtlBC::PERIODIC } }; - const std::vector decomp { -1 }; - - const std::vector species_params { ParticleSpecies { - static_cast(1), - "e-", - 1.0f, - -1.0f, - static_cast(10), - timestep_t { 0 }, - timestep_t { 0 }, - ParticlePusher::BORIS, - false, - RadiativeDrag::NONE, - EmissionType::NONE, - static_cast(0), - static_cast(0) } }; + const boundaries_t init_extent { + { static_cast(0.0), static_cast(10.0) } + }; + const boundaries_t fldsbc { + { FldsBC::PERIODIC, FldsBC::PERIODIC } + }; + const boundaries_t prtlbc { + { PrtlBC::PERIODIC, PrtlBC::PERIODIC } + }; + const std::vector decomp { -1 }; + + const std::vector species_params { + ParticleSpecies { static_cast(1), + "e-", 1.0f, + -1.0f, + static_cast(10), + timestep_t { 0 }, + timestep_t { 0 }, + ParticlePusher::BORIS, + false, RadiativeDrag::NONE, + EmissionType::NONE, + static_cast(0), + static_cast(0) } + }; #if !defined(MPI_ENABLED) - const unsigned int ndomains { 1 }; - adios2::ADIOS adios; + const unsigned int ndomains { 1 }; + adios2::ADIOS adios; // non-MPI: single domain, sizes always match (equal-sizes path) const std::vector saved_ncells_per_dom { 64 }; #else @@ -85,7 +89,7 @@ auto main(int argc, char* argv[]) -> int { raise::ErrorIf(mpi_size != 2, "this test requires exactly 2 MPI ranks", HERE); // asymmetric split: 40+24=64; exercises redecomposeFromCheckpoint const std::vector saved_ncells_per_dom { 40, 24 }; - const real_t x_split = init_extent[0].second * + const real_t x_split = init_extent[0].second * static_cast(saved_ncells_per_dom[0]) / static_cast(64); #endif @@ -99,9 +103,8 @@ auto main(int argc, char* argv[]) -> int { // ── Write phase ─────────────────────────────────────────────────────────── { - Metadomain md { - ndomains, decomp, res, init_extent, fldsbc, prtlbc, {}, species_params - }; + Metadomain md { ndomains, decomp, res, init_extent, + fldsbc, prtlbc, {}, species_params }; #if defined(MPI_ENABLED) // Simulate load balancing: [32, 32] → [40, 24] @@ -111,7 +114,7 @@ auto main(int argc, char* argv[]) -> int { { { x_split, init_extent[0].second } } }); #endif - auto* local = md.subdomain_ptr(md.l_subdomain_indices()[0]); + auto* local = md.subdomain_ptr(md.l_subdomain_indices()[0]); const auto n_all = local->mesh.n_all()[0]; // set em::ex1(i) = real_t(i) over all cells including ghost cells @@ -129,10 +132,10 @@ auto main(int argc, char* argv[]) -> int { { auto i1_h = Kokkos::create_mirror_view(sp.i1); auto dx1_h = Kokkos::create_mirror_view(sp.dx1); - i1_h(0) = prtl_i1_0; - dx1_h(0) = static_cast(prtl_dx1_0); - i1_h(1) = prtl_i1_1; - dx1_h(1) = static_cast(prtl_dx1_1); + i1_h(0) = prtl_i1_0; + dx1_h(0) = static_cast(prtl_dx1_0); + i1_h(1) = prtl_i1_1; + dx1_h(1) = static_cast(prtl_dx1_1); Kokkos::deep_copy(sp.i1, i1_h); Kokkos::deep_copy(sp.dx1, dx1_h); } @@ -147,12 +150,11 @@ auto main(int argc, char* argv[]) -> int { md.InitCheckpointWriter(&adios, params); - const auto wrote = md.WriteCheckpoint( - params, - checkpoint_step, - checkpoint_step, - simtime_t { 0.0 }, - simtime_t { 0.0 }); + const auto wrote = md.WriteCheckpoint(params, + checkpoint_step, + checkpoint_step, + simtime_t { 0.0 }, + simtime_t { 0.0 }); raise::ErrorIf(not wrote, "checkpoint was not written", HERE); } @@ -160,9 +162,9 @@ auto main(int argc, char* argv[]) -> int { { // fresh metadomain with the original (uniform) decomposition // MPI: [32, 32] — mismatch with saved [40, 24] → reconstruction triggered - Metadomain md2 { - ndomains, decomp, res, init_extent, fldsbc, prtlbc, {}, species_params - }; + Metadomain md2 { ndomains, decomp, res, + init_extent, fldsbc, prtlbc, + {}, species_params }; SimulationParams params2; params2.set("checkpoint.read_path", std::string { CHECKPOINT_DIR }); @@ -170,18 +172,17 @@ auto main(int argc, char* argv[]) -> int { md2.ContinueFromCheckpoint(&adios, params2); - auto* local = md2.subdomain_ptr(md2.l_subdomain_indices()[0]); - const auto lidx = md2.l_subdomain_indices()[0]; - const auto exp_ncells = saved_ncells_per_dom[lidx]; - const auto exp_n_all = exp_ncells + 2 * N_GHOSTS; + auto* local = md2.subdomain_ptr(md2.l_subdomain_indices()[0]); + const auto lidx = md2.l_subdomain_indices()[0]; + const auto exp_ncells = saved_ncells_per_dom[lidx]; + const auto exp_n_all = exp_ncells + 2 * N_GHOSTS; // 1. field array size reflects saved (possibly reconstructed) ncells - raise::ErrorIf( - local->fields.em.extent(0) != exp_n_all, - fmt::format("field em extent: got %lu, expected %lu", - local->fields.em.extent(0), - exp_n_all), - HERE); + raise::ErrorIf(local->fields.em.extent(0) != exp_n_all, + fmt::format("field em extent: got %lu, expected %lu", + local->fields.em.extent(0), + exp_n_all), + HERE); // 2. field values survive the round-trip { @@ -200,12 +201,11 @@ auto main(int argc, char* argv[]) -> int { // 3. particle count and coordinates survive the round-trip auto& sp = local->species[0]; - raise::ErrorIf( - sp.npart() != npart_placed, - fmt::format("particle count: got %lu, expected %lu", - sp.npart(), - npart_placed), - HERE); + raise::ErrorIf(sp.npart() != npart_placed, + fmt::format("particle count: got %lu, expected %lu", + sp.npart(), + npart_placed), + HERE); { auto i1_h = Kokkos::create_mirror_view(sp.i1); auto dx1_h = Kokkos::create_mirror_view(sp.dx1); @@ -233,12 +233,16 @@ auto main(int argc, char* argv[]) -> int { } catch (const std::exception& e) { std::cerr << e.what() << '\n'; - cleanup(); + CallOnce([&] { + cleanup(); + }); GlobalFinalize(); return 1; } - cleanup(); + CallOnce([&] { + cleanup(); + }); GlobalFinalize(); return 0; } diff --git a/tests/framework/checkpoint-extents.cpp b/tests/framework/checkpoint-extents.cpp index ecf6e5793..90a947867 100644 --- a/tests/framework/checkpoint-extents.cpp +++ b/tests/framework/checkpoint-extents.cpp @@ -9,11 +9,11 @@ #include "utils/comparators.h" #include "utils/error.h" +#include "metrics/minkowski.h" + #include "framework/domain/metadomain.h" #include "framework/parameters/parameters.h" -#include "metrics/minkowski.h" - #include #include #include @@ -36,8 +36,8 @@ void cleanup() { std::filesystem::remove_all(CHECKPOINT_DIR); } -auto extents_match(const boundaries_t& a, - const boundaries_t& b) -> bool { +auto extents_match(const boundaries_t& a, const boundaries_t& b) + -> bool { if (a.size() != b.size()) { return false; } @@ -57,9 +57,10 @@ auto main(int argc, char* argv[]) -> int { using M = Minkowski; const std::vector res { 64 }; - const boundaries_t init_extent { { static_cast(0.0), - static_cast(10.0) } }; - const boundaries_t fldsbc { + const boundaries_t init_extent { + { static_cast(0.0), static_cast(10.0) } + }; + const boundaries_t fldsbc { { FldsBC::PERIODIC, FldsBC::PERIODIC } }; const boundaries_t prtlbc { @@ -85,9 +86,8 @@ auto main(int argc, char* argv[]) -> int { std::vector> expected_subdomain_extents(ndomains); { - Metadomain md { - ndomains, decomp, res, init_extent, fldsbc, prtlbc, {}, {} - }; + Metadomain md { ndomains, decomp, res, init_extent, + fldsbc, prtlbc, {}, {} }; SimulationParams params; params.set("checkpoint.write_path", std::string { CHECKPOINT_DIR }); @@ -107,26 +107,24 @@ auto main(int argc, char* argv[]) -> int { } // write checkpoint at step 2 (finished_step must be > 1 to be saved) - const auto wrote = md.WriteCheckpoint( - params, - checkpoint_step, - checkpoint_step, - simtime_t { 0.0 }, - simtime_t { 0.0 }); + const auto wrote = md.WriteCheckpoint(params, + checkpoint_step, + checkpoint_step, + simtime_t { 0.0 }, + simtime_t { 0.0 }); raise::ErrorIf(not wrote, "checkpoint was not written", HERE); } { // construct a fresh metadomain from the original (pre-shift) extent - Metadomain md2 { - ndomains, decomp, res, init_extent, fldsbc, prtlbc, {}, {} - }; + Metadomain md2 { ndomains, decomp, res, init_extent, + fldsbc, prtlbc, {}, {} }; // sanity: verify global extent is the original one before reading - raise::ErrorIf( - extents_match(md2.mesh().extent(), expected_global_extent), - "global extent should differ from shifted extent before checkpoint read", - HERE); + raise::ErrorIf(extents_match(md2.mesh().extent(), expected_global_extent), + "global extent should differ from shifted extent before " + "checkpoint read", + HERE); SimulationParams params2; params2.set("checkpoint.read_path", std::string { CHECKPOINT_DIR }); @@ -135,29 +133,31 @@ auto main(int argc, char* argv[]) -> int { md2.ContinueFromCheckpoint(&adios, params2); // global mesh extent must match the shifted one - raise::ErrorIf( - not extents_match(md2.mesh().extent(), expected_global_extent), - "global mesh extent mismatch after checkpoint read", - HERE); + raise::ErrorIf(not extents_match(md2.mesh().extent(), expected_global_extent), + "global mesh extent mismatch after checkpoint read", + HERE); // per-subdomain extents must also match for (unsigned int idx { 0 }; idx < ndomains; ++idx) { - raise::ErrorIf( - not extents_match(md2.subdomain(idx).mesh.extent(), - expected_subdomain_extents[idx]), - "subdomain extent mismatch after checkpoint read", - HERE); + raise::ErrorIf(not extents_match(md2.subdomain(idx).mesh.extent(), + expected_subdomain_extents[idx]), + "subdomain extent mismatch after checkpoint read", + HERE); } } } catch (const std::exception& e) { std::cerr << e.what() << '\n'; - cleanup(); + CallOnce([&] { + cleanup(); + }); GlobalFinalize(); return 1; } - cleanup(); + CallOnce([&] { + cleanup(); + }); GlobalFinalize(); return 0; } diff --git a/tests/framework/particles_sort.cpp b/tests/framework/particles_sort.cpp index a65131706..5af7e98c2 100644 --- a/tests/framework/particles_sort.cpp +++ b/tests/framework/particles_sort.cpp @@ -95,15 +95,17 @@ auto main(int argc, char* argv[]) -> int { raise::ErrorIf(weight_h(p) != -1.0, "error in sorting particles", HERE); } if (p < 59u) { - raise::ErrorIf(pld_r_h(p, 0) != weight_h(p) + 0.5, + raise::ErrorIf(pld_r_h(p, 0) != weight_h(p) + static_cast(0.5), "error in sorting particle real payload 0", HERE); - raise::ErrorIf(pld_r_h(p, 1) != weight_h(p) + 10.5, + raise::ErrorIf(pld_r_h(p, 1) != weight_h(p) + static_cast(10.5), "error in sorting particle real payload 1", HERE); - raise::ErrorIf(pld_i_h(p, 0) != static_cast(weight_h(p) + 10.0), - "error in sorting particle integer payload 0", - HERE); + raise::ErrorIf( + pld_i_h(p, 0) != + static_cast(weight_h(p) + static_cast(10.0)), + "error in sorting particle integer payload 0", + HERE); } } } diff --git a/tests/global/tiling.cpp b/tests/global/tiling.cpp index f9dc68198..67c84f573 100644 --- a/tests/global/tiling.cpp +++ b/tests/global/tiling.cpp @@ -27,7 +27,7 @@ Inline void CheckValue(index_t p, const array_t&, const array_t& tag, const array_t& tile_indices, - ncells_t nt1, + ncells_t, ncells_t, ncells_t, ncells_t ntiles, @@ -51,8 +51,8 @@ Inline void CheckValue(index_t p, const array_t&, const array_t& tag, const array_t& tile_indices, - ncells_t nt1, - ncells_t nt2, + ncells_t, + ncells_t nt2, ncells_t, ncells_t ntiles, ncells_t ts) { @@ -62,8 +62,8 @@ Inline void CheckValue(index_t p, } return; } - const auto ti = static_cast(i2(p) / ts) * nt1 + - static_cast(i1(p) / ts); + const auto ti = static_cast(i1(p) / ts) * nt2 + + static_cast(i2(p) / ts); if (tile_indices(p) != ti) { raise::KernelError(HERE, "Alive particle assigned to wrong tile index"); } @@ -76,21 +76,21 @@ Inline void CheckValue(index_t p, const array_t& i3, const array_t& tag, const array_t& tile_indices, - ncells_t nt1, - ncells_t nt2, - ncells_t nt3, - ncells_t ntiles, - ncells_t ts) { + ncells_t, + ncells_t nt2, + ncells_t nt3, + ncells_t ntiles, + ncells_t ts) { if (tag(p) != ntt::ParticleTag::alive) { if (tile_indices(p) != ntiles + 1u) { raise::KernelError(HERE, "Dead particle assigned to wrong tile index"); } return; } - const auto ti = (static_cast(i3(p) / ts) * nt2 + + const auto ti = (static_cast(i1(p) / ts) * nt2 + static_cast(i2(p) / ts)) * - nt1 + - static_cast(i1(p) / ts); + nt3 + + static_cast(i3(p) / ts); if (tile_indices(p) != ti) { raise::KernelError(HERE, "Alive particle assigned to wrong tile index"); } @@ -170,9 +170,9 @@ auto main(int argc, char* argv[]) -> int { npart, Lambda(index_t p) { auto gen = random_pool.get_state(); - i1(p) = gen.urand(0u, nx1); - i2(p) = gen.urand(0u, nx2); - i3(p) = gen.urand(0u, nx3); + i1(p) = static_cast(gen.urand(0u, nx1)); + i2(p) = static_cast(gen.urand(0u, nx2)); + i3(p) = static_cast(gen.urand(0u, nx3)); tag(p) = (gen.drand() > 0.01) ? ParticleTag::alive : ParticleTag::dead; random_pool.free_state(gen); if (tag(p) == ParticleTag::dead) { @@ -218,9 +218,9 @@ auto main(int argc, char* argv[]) -> int { npart, Lambda(index_t p) { const auto cell_idx = p % ncells; - i1(p) = cell_idx % nx1; - i2(p) = cell_idx / nx1; - tag(p) = ParticleTag::alive; + i1(p) = static_cast(cell_idx) % static_cast(nx1); + i2(p) = static_cast(cell_idx) / static_cast(nx1); + tag(p) = ParticleTag::alive; }); Kokkos::parallel_for("Tiling", npart, @@ -238,8 +238,8 @@ auto main(int argc, char* argv[]) -> int { npart, Lambda(index_t p) { const auto tile_idx = tile_indices(p); - const auto t1 = tile_idx % nt1; - const auto t2 = tile_idx / nt1; + const auto t1 = tile_idx / nt2; + const auto t2 = tile_idx % nt2; const auto i1_min = t1 * tile_size; const auto i1_max = math::min(i1_min + tile_size, nx1); const auto i2_min = t2 * tile_size; @@ -275,8 +275,8 @@ auto main(int argc, char* argv[]) -> int { } current_tile = ti_h(p); } - const auto t1 = current_tile % nt1; - const auto t2 = current_tile / nt1; + const auto t1 = current_tile / nt2; + const auto t2 = current_tile % nt2; const auto i1_min = t1 * tile_size; const auto i1_max = math::min(i1_min + tile_size, nx1); const auto i2_min = t2 * tile_size; @@ -305,7 +305,7 @@ auto main(int argc, char* argv[]) -> int { } } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/global/traits_policies.cpp b/tests/global/traits_policies.cpp index 8c02dd4ad..217b687ad 100644 --- a/tests/global/traits_policies.cpp +++ b/tests/global/traits_policies.cpp @@ -3,6 +3,7 @@ #include "traits/policies.h" #include "utils/numeric.h" +#include "framework/containers/particles.h" #include "kernels/pushers/context.h" #include @@ -120,7 +121,7 @@ struct ValidCustomPrtlUpdate { void operator()(index_t, const kernel::sr::PusherContext&, const kernel::sr::PusherBoundaries&, - const kernel::PusherArrays&, + const ntt::ParticleArrays&, const MockMetric&) const {} }; @@ -131,7 +132,7 @@ struct BadCustomPrtlUpdate { void operator()(index_t, const kernel::sr::PusherContext&, const kernel::sr::PusherBoundaries&, - const kernel::PusherArrays&) const {} + const ntt::ParticleArrays&) const {} }; static_assert(not CustomParticleUpdatePolicyClass); diff --git a/tests/kernels/custom_emission.cpp b/tests/kernels/custom_emission.cpp index f23d272c8..1a407bc6b 100644 --- a/tests/kernels/custom_emission.cpp +++ b/tests/kernels/custom_emission.cpp @@ -101,13 +101,13 @@ struct EmissionPolicy { , sp2_tag { sp2_tag } , sp2_pld_i { sp2_pld_i } {} - Inline auto shouldEmit(const coord_t& x_Cd, - const coord_t& x_Ph, - const vec_t& u_Ph, + Inline auto shouldEmit(const coord_t& /*x_Cd*/, + const coord_t& /*x_Ph*/, + const vec_t& /*u_Ph*/, const vec_t&, const vec_t&, vec_t& delta_u_Ph, - Payload& payload) const -> Kokkos::pair { + Payload& /*payload*/) const -> Kokkos::pair { delta_u_Ph[0] = -TWO; delta_u_Ph[1] = ZERO; delta_u_Ph[2] = ZERO; @@ -232,8 +232,6 @@ auto main(int argc, char* argv[]) -> int { 0u, 0u); - auto pusher_arrays = emitting_species.PusherKernelArrays(); - const auto boundaries = kernel::sr::PusherBoundaries { { { PrtlBC::PERIODIC, PrtlBC::PERIODIC } } }; @@ -292,7 +290,7 @@ auto main(int argc, char* argv[]) -> int { 1u, 1u }, boundaries, - pusher_arrays, + emitting_species, EB, metric, pusher_policy)); @@ -337,7 +335,7 @@ auto main(int argc, char* argv[]) -> int { } } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; ntt::GlobalFinalize(); return 1; } diff --git a/tests/kernels/custom_prtl_update.cpp b/tests/kernels/custom_prtl_update.cpp index 7b5b94a33..2b2aae8d0 100644 --- a/tests/kernels/custom_prtl_update.cpp +++ b/tests/kernels/custom_prtl_update.cpp @@ -7,6 +7,7 @@ #include "metrics/minkowski.h" +#include "framework/containers/particles.h" #include "kernels/pushers/context.h" #include "kernels/pushers/sr.hpp" @@ -49,8 +50,8 @@ struct TestCustomPrtlUpdate { Inline void operator()(index_t p, const kernel::sr::PusherContext& ctx, const kernel::sr::PusherBoundaries&, - const kernel::PusherArrays& particles, - const M& metric) const { + const ntt::ParticleArrays& particles, + const M& /*metric*/) const { if constexpr (M::Dim == Dim::_1D || M::Dim == Dim::_2D || M::Dim == Dim::_3D) { auto invert_vel = false; if (particles.i1(p) < 0) { @@ -120,7 +121,8 @@ void testCustomPrtlUpdate(const std::vector& res, nx3 = static_cast(res.at(2)); } - const real_t dt = 0.1 * (ext.at(0).second - ext.at(0).first) / + const real_t dt = static_cast(0.1) * + (ext.at(0).second - ext.at(0).first) / static_cast(nx1); ndfield_t emfield; @@ -201,7 +203,7 @@ void testCustomPrtlUpdate(const std::vector& res, { PrtlBC::REFLECT, PrtlBC::REFLECT } } }; - kernel::PusherArrays r_arrays { 1u }; + ntt::ParticleArrays r_arrays { 1u }; r_arrays.i1 = r_i1; r_arrays.i2 = r_i2; r_arrays.i3 = r_i3; @@ -220,7 +222,7 @@ void testCustomPrtlUpdate(const std::vector& res, r_arrays.phi = phi; r_arrays.tag = r_tag; - kernel::PusherArrays c_arrays { 2u }; + ntt::ParticleArrays c_arrays { 2u }; c_arrays.i1 = c_i1; c_arrays.i2 = c_i2; c_arrays.i3 = c_i3; @@ -249,21 +251,39 @@ void testCustomPrtlUpdate(const std::vector& res, static constexpr auto n_iter = 100; for (auto n { 0 }; n < n_iter; ++n) { - Kokkos::parallel_for( - "pusher_reflect", - CreateRangePolicy({ 0 }, { 1 }), - kernel::sr::Pusher_kernel( - { 1u, ParticlePusher::BORIS, RadiativeDrag::NONE, 1.f, 1.f, dt * n, dt, ONE, nx1, nx2, nx3 }, - boundaries, - r_arrays, - emfield, - metric)); + Kokkos::parallel_for("pusher_reflect", + CreateRangePolicy({ 0 }, { 1 }), + kernel::sr::Pusher_kernel({ 1u, + ParticlePusher::BORIS, + RadiativeDrag::NONE, + 1.f, + 1.f, + dt * static_cast(n), + dt, + ONE, + nx1, + nx2, + nx3 }, + boundaries, + r_arrays, + emfield, + metric)); Kokkos::parallel_for( "pusher_custom", CreateRangePolicy({ 0 }, { 1 }), kernel::sr::Pusher_kernel( - { 2u, ParticlePusher::BORIS, RadiativeDrag::NONE, 1.f, 1.f, dt * n, dt, ONE, nx1, nx2, nx3 }, + { 2u, + ParticlePusher::BORIS, + RadiativeDrag::NONE, + 1.f, + 1.f, + dt * static_cast(n), + dt, + ONE, + nx1, + nx2, + nx3 }, boundaries, c_arrays, emfield, @@ -354,7 +374,7 @@ auto main(int argc, char* argv[]) -> int { testCustomPrtlUpdate>(res3d, ext3d, {}); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/ext_force.cpp b/tests/kernels/ext_force.cpp index b278062d4..3d1ee76b8 100644 --- a/tests/kernels/ext_force.cpp +++ b/tests/kernels/ext_force.cpp @@ -81,9 +81,9 @@ void testPusher(const std::vector& res) { {} }; - const int nx1 = res[0]; - const int nx2 = res[1]; - const int nx3 = res[2]; + const auto nx1 = static_cast(res[0]); + const auto nx2 = static_cast(res[1]); + const auto nx3 = static_cast(res[2]); const auto range_ext = CreateRangePolicy( { 0, 0, 0 }, @@ -135,9 +135,9 @@ void testPusher(const std::vector& res) { put_value(i1, (int)(x1_0), 0); put_value(i2, (int)(x2_0), 0); put_value(i3, (int)(x3_0), 0); - put_value(dx1, (prtldx_t)(x1_0 - (int)(x1_0)), 0); - put_value(dx2, (prtldx_t)(x2_0 - (int)(x2_0)), 0); - put_value(dx3, (prtldx_t)(x3_0 - (int)(x3_0)), 0); + put_value(dx1, (prtldx_t)(x1_0 - math::floor(x1_0)), 0); + put_value(dx2, (prtldx_t)(x2_0 - math::floor(x2_0)), 0); + put_value(dx3, (prtldx_t)(x3_0 - math::floor(x3_0)), 0); put_value(ux1, ux1_0, 0); put_value(ux2, ux2_0, 0); put_value(ux3, ux3_0, 0); @@ -146,9 +146,9 @@ void testPusher(const std::vector& res) { put_value(i1, (int)(x1_0), 1); put_value(i2, (int)(x2_0), 1); put_value(i3, (int)(x3_0), 1); - put_value(dx1, (prtldx_t)(x1_0 - (int)(x1_0)), 1); - put_value(dx2, (prtldx_t)(x2_0 - (int)(x2_0)), 1); - put_value(dx3, (prtldx_t)(x3_0 - (int)(x3_0)), 1); + put_value(dx1, (prtldx_t)(x1_0 - math::floor(x1_0)), 1); + put_value(dx2, (prtldx_t)(x2_0 - math::floor(x2_0)), 1); + put_value(dx3, (prtldx_t)(x3_0 - math::floor(x3_0)), 1); put_value(ux1, -ux1_0, 1); put_value(ux2, -ux2_0, 1); put_value(ux3, -ux3_0, 1); @@ -169,7 +169,7 @@ void testPusher(const std::vector& res) { { PrtlBC::PERIODIC, PrtlBC::PERIODIC } } }; - kernel::PusherArrays pusher_arrays { 1u }; + ntt::ParticleArrays pusher_arrays { 1u }; pusher_arrays.i1 = i1; pusher_arrays.i2 = i2; pusher_arrays.i3 = i3; @@ -196,7 +196,7 @@ void testPusher(const std::vector& res) { false> { {}, {}, ext_force }; for (auto t { 0u }; t < 100; ++t) { - const real_t time = t * dt; + const real_t time = static_cast(t) * dt; Kokkos::parallel_for( "pusher", @@ -288,7 +288,7 @@ auto main(int argc, char* argv[]) -> int { testPusher>({ 10, 10, 10 }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/gca_pusher.cpp b/tests/kernels/gca_pusher.cpp index 5e57f1b75..7ec9bd769 100644 --- a/tests/kernels/gca_pusher.cpp +++ b/tests/kernels/gca_pusher.cpp @@ -7,6 +7,7 @@ #include "metrics/minkowski.h" +#include "framework/containers/particles.h" #include "kernels/pushers/context.h" #include "kernels/pushers/sr.hpp" @@ -62,9 +63,9 @@ void testPusher(const std::vector& res) { {} }; - const int nx1 = res[0]; - const int nx2 = res[1]; - const int nx3 = res[2]; + const auto nx1 = static_cast(res[0]); + const auto nx2 = static_cast(res[1]); + const auto nx3 = static_cast(res[2]); const auto range_ext = CreateRangePolicy( { 0, 0, 0 }, @@ -122,9 +123,9 @@ void testPusher(const std::vector& res) { put_value(i1, (int)(x1_0), 0); put_value(i2, (int)(x2_0), 0); put_value(i3, (int)(x3_0), 0); - put_value(dx1, (prtldx_t)(x1_0 - (int)(x1_0)), 0); - put_value(dx2, (prtldx_t)(x2_0 - (int)(x2_0)), 0); - put_value(dx3, (prtldx_t)(x3_0 - (int)(x3_0)), 0); + put_value(dx1, (prtldx_t)(x1_0 - math::floor(x1_0)), 0); + put_value(dx2, (prtldx_t)(x2_0 - math::floor(x2_0)), 0); + put_value(dx3, (prtldx_t)(x3_0 - math::floor(x3_0)), 0); put_value(ux1, ux1_0, 0); put_value(ux2, ux2_0, 0); put_value(ux3, ux3_0, 0); @@ -133,9 +134,9 @@ void testPusher(const std::vector& res) { put_value(i1, (int)(x1_0), 1); put_value(i2, (int)(x2_0), 1); put_value(i3, (int)(x3_0), 1); - put_value(dx1, (prtldx_t)(x1_0 - (int)(x1_0)), 1); - put_value(dx2, (prtldx_t)(x2_0 - (int)(x2_0)), 1); - put_value(dx3, (prtldx_t)(x3_0 - (int)(x3_0)), 1); + put_value(dx1, (prtldx_t)(x1_0 - math::floor(x1_0)), 1); + put_value(dx2, (prtldx_t)(x2_0 - math::floor(x2_0)), 1); + put_value(dx3, (prtldx_t)(x3_0 - math::floor(x3_0)), 1); put_value(ux1, -ux1_0, 1); put_value(ux2, -ux2_0, 1); put_value(ux3, -ux3_0, 1); @@ -150,7 +151,7 @@ void testPusher(const std::vector& res) { }; const auto gca_context = kernel::sr::PusherGCAContext { 10000.0, ONE }; - kernel::PusherArrays pusher_arrays { 1u }; + ntt::ParticleArrays pusher_arrays { 1u }; pusher_arrays.i1 = i1; pusher_arrays.i2 = i2; pusher_arrays.i3 = i3; @@ -176,7 +177,7 @@ void testPusher(const std::vector& res) { RadiativeDrag::NONE, 1.f, 1.f, - t * dt, + static_cast(t) * dt, dt, omegaB0, nx1, @@ -219,7 +220,7 @@ auto main(int argc, char* argv[]) -> int { testPusher>({ 10, 10, 10 }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/prtl_bc.cpp b/tests/kernels/prtl_bc.cpp index 061cd03cc..037d59035 100644 --- a/tests/kernels/prtl_bc.cpp +++ b/tests/kernels/prtl_bc.cpp @@ -7,6 +7,7 @@ #include "metrics/minkowski.h" +#include "framework/containers/particles.h" #include "kernels/pushers/context.h" #include "kernels/pushers/sr.hpp" @@ -75,7 +76,8 @@ void testPeriodicBC(const std::vector& res, nx3 = static_cast(res.at(2)); } - const real_t dt = 0.1 * (ext.at(0).second - ext.at(0).first) / sx; + const real_t dt = static_cast(0.1) * + (ext.at(0).second - ext.at(0).first) / sx; const real_t coeff = HALF * dt; ndfield_t emfield; @@ -117,27 +119,27 @@ void testPeriodicBC(const std::vector& res, real_t xi_1 = ZERO, yi_1 = ZERO, zi_1 = ZERO; real_t xi_2 = ZERO, yi_2 = ZERO, zi_2 = ZERO; if constexpr (M::Dim == Dim::_1D or M::Dim == Dim::_2D or M::Dim == Dim::_3D) { - xi_1 = 0.515460 * sx + ext.at(0).first; - xi_2 = 0.149088 * sx + ext.at(0).first; + xi_1 = static_cast(0.515460) * sx + ext.at(0).first; + xi_2 = static_cast(0.149088) * sx + ext.at(0).first; } if constexpr (M::Dim == Dim::_2D or M::Dim == Dim::_3D) { - yi_1 = 0.340680 * sy + ext.at(1).first; - yi_2 = 0.997063 * sy + ext.at(1).first; + yi_1 = static_cast(0.340680) * sy + ext.at(1).first; + yi_2 = static_cast(0.997063) * sy + ext.at(1).first; } if constexpr (M::Dim == Dim::_3D) { - zi_1 = 0.940722 * sz + ext.at(2).first; - zi_2 = 0.607354 * sz + ext.at(2).first; + zi_1 = static_cast(0.940722) * sz + ext.at(2).first; + zi_2 = static_cast(0.607354) * sz + ext.at(2).first; } real_t ux_1 = 0.569197; real_t uy_1 = 0.716085; real_t uz_1 = 0.760101; - real_t gamma_1 = math::sqrt(1.0 + SQR(ux_1) + SQR(uy_1) + SQR(uz_1)); + real_t gamma_1 = math::sqrt(ONE + SQR(ux_1) + SQR(uy_1) + SQR(uz_1)); // init parameters of prtl #2 real_t ux_2 = -0.872069; real_t uy_2 = 0.0484461; real_t uz_2 = -0.613575; - real_t gamma_2 = math::sqrt(1.0 + SQR(ux_2) + SQR(uy_2) + SQR(uz_2)); + real_t gamma_2 = math::sqrt(ONE + SQR(ux_2) + SQR(uy_2) + SQR(uz_2)); { coord_t xCd { ZERO }, xi { ZERO }; @@ -237,7 +239,7 @@ void testPeriodicBC(const std::vector& res, { PrtlBC::PERIODIC, PrtlBC::PERIODIC } } }; - kernel::PusherArrays pusher_arrays { 1u }; + ntt::ParticleArrays pusher_arrays { 1u }; pusher_arrays.i1 = i1; pusher_arrays.i2 = i2; pusher_arrays.i3 = i3; diff --git a/tests/kernels/pusher.cpp b/tests/kernels/pusher.cpp index c418726a5..ad571555d 100644 --- a/tests/kernels/pusher.cpp +++ b/tests/kernels/pusher.cpp @@ -2,7 +2,6 @@ #include "global.h" #include "arch/kokkos_aliases.h" -#include "traits/policies.h" #include "utils/error.h" #include "utils/numeric.h" @@ -63,9 +62,9 @@ void testPusher(const std::vector& res) { {} }; - const int nx1 = res[0]; - const int nx2 = res[1]; - const int nx3 = res[2]; + const auto nx1 = static_cast(res[0]); + const auto nx2 = static_cast(res[1]); + const auto nx3 = static_cast(res[2]); const auto range_ext = CreateRangePolicy( { 0, 0, 0 }, @@ -118,9 +117,9 @@ void testPusher(const std::vector& res) { put_value(i1, (int)(x1_0), 0); put_value(i2, (int)(x2_0), 0); put_value(i3, (int)(x3_0), 0); - put_value(dx1, (prtldx_t)(x1_0 - (int)(x1_0)), 0); - put_value(dx2, (prtldx_t)(x2_0 - (int)(x2_0)), 0); - put_value(dx3, (prtldx_t)(x3_0 - (int)(x3_0)), 0); + put_value(dx1, (prtldx_t)(x1_0 - math::floor(x1_0)), 0); + put_value(dx2, (prtldx_t)(x2_0 - math::floor(x2_0)), 0); + put_value(dx3, (prtldx_t)(x3_0 - math::floor(x3_0)), 0); put_value(ux1, ux1_0, 0); put_value(ux2, ux2_0, 0); put_value(ux3, ux3_0, 0); @@ -129,9 +128,9 @@ void testPusher(const std::vector& res) { put_value(i1, (int)(x1_0), 1); put_value(i2, (int)(x2_0), 1); put_value(i3, (int)(x3_0), 1); - put_value(dx1, (prtldx_t)(x1_0 - (int)(x1_0)), 1); - put_value(dx2, (prtldx_t)(x2_0 - (int)(x2_0)), 1); - put_value(dx3, (prtldx_t)(x3_0 - (int)(x3_0)), 1); + put_value(dx1, (prtldx_t)(x1_0 - math::floor(x1_0)), 1); + put_value(dx2, (prtldx_t)(x2_0 - math::floor(x2_0)), 1); + put_value(dx3, (prtldx_t)(x3_0 - math::floor(x3_0)), 1); put_value(ux1, ux1_0, 1); put_value(ux2, ux2_0, 1); put_value(ux3, ux3_0, 1); @@ -151,7 +150,7 @@ void testPusher(const std::vector& res) { { PrtlBC::PERIODIC, PrtlBC::PERIODIC } } }; - kernel::PusherArrays pusher_arrays { 1u }; + ntt::ParticleArrays pusher_arrays { 1u }; pusher_arrays.i1 = i1; pusher_arrays.i2 = i2; pusher_arrays.i3 = i3; @@ -171,7 +170,7 @@ void testPusher(const std::vector& res) { pusher_arrays.tag = tag; for (auto t { 0u }; t < 2000; ++t) { - const real_t time = t * dt; + const real_t time = static_cast(t) * dt; Kokkos::parallel_for("pusher", CreateRangePolicy({ 0 }, { 1 }), @@ -283,7 +282,7 @@ auto main(int argc, char* argv[]) -> int { testPusher>({ 10, 10, 10 }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } From 2aa65ca681015d17f08c03f0e0df337cfa9fc268 Mon Sep 17 00:00:00 2001 From: haykh Date: Mon, 4 May 2026 17:44:04 -0400 Subject: [PATCH 10/12] consistent integer sizing across the code --- .../examples/custom_particle_update/pgen.hpp | 2 +- pgens/examples/piston/pgen.hpp | 2 +- pgens/examples/tutorial_cartesian_sr/pgen.hpp | 6 +- pgens/shock/pgen.hpp | 4 +- pgens/turbulence/pgen.hpp | 4 +- src/archetypes/field_setter.h | 12 ++-- src/archetypes/moving_window.h | 16 ++--- src/archetypes/piston.h | 4 +- src/engines/engine.hpp | 2 +- src/engines/grpic/currents.h | 2 +- src/engines/grpic/fields_bcs.h | 4 +- src/engines/grpic/grpic.hpp | 2 +- src/engines/srpic/fields_bcs.h | 12 ++-- src/framework/containers/fields_io.cpp | 13 ++-- src/framework/containers/particles.h | 10 +-- src/framework/containers/particles_io.cpp | 4 +- src/framework/containers/particles_sort.cpp | 18 +++-- src/framework/domain/comm_mpi.hpp | 34 ++++----- src/framework/domain/comm_nompi.hpp | 28 ++++---- src/framework/domain/metadomain.h | 4 +- src/framework/domain/metadomain_chckpt.cpp | 26 +++---- src/framework/domain/metadomain_comm.cpp | 57 ++++++++------- src/framework/domain/metadomain_io.cpp | 35 +++++----- src/global/arch/kokkos_aliases.cpp | 70 ++++++++++++------- src/global/arch/kokkos_aliases.h | 10 ++- src/global/global.h | 43 ++++++++---- src/global/traits/pgen.h | 2 +- src/global/traits/policies.h | 2 +- src/global/utils/error.h | 1 + src/global/utils/sorting.h | 2 +- src/kernels/ampere_gr.hpp | 4 +- src/kernels/ampere_mink.hpp | 12 ++-- src/kernels/ampere_sr.hpp | 8 +-- src/kernels/aux_fields_gr.hpp | 12 ++-- src/kernels/comm.hpp | 14 ++-- src/kernels/currents_deposit.hpp | 2 +- src/kernels/digital_filter.hpp | 6 +- src/kernels/divergences.hpp | 6 +- src/kernels/faraday_gr.hpp | 16 ++--- src/kernels/faraday_mink.hpp | 6 +- src/kernels/faraday_sr.hpp | 4 +- src/kernels/fields_bcs.hpp | 46 ++++++------ src/kernels/fields_to_phys.hpp | 6 +- src/kernels/injectors.hpp | 14 ++-- src/kernels/particle_moments.hpp | 12 ++-- src/kernels/prtls_to_phys.hpp | 8 +-- src/kernels/pushers/gr.hpp | 16 ++--- src/kernels/pushers/sr.hpp | 26 +++---- src/kernels/reduced_stats.hpp | 8 +-- src/kernels/utils.hpp | 6 +- src/metrics/kerr_schild.h | 5 +- src/metrics/kerr_schild_0.h | 5 +- src/metrics/qkerr_schild.h | 3 +- src/metrics/spherical.h | 2 +- src/output/utils/readers.cpp | 18 +++-- src/output/utils/writers.cpp | 9 ++- src/output/writer.cpp | 29 ++++---- src/output/writer.h | 6 +- tests/archetypes/energy_dist.cpp | 4 +- tests/archetypes/field_setter.cpp | 4 +- tests/archetypes/pgen.cpp | 2 +- tests/archetypes/powerlaw.cpp | 4 +- tests/archetypes/spatial_dist.cpp | 4 +- tests/framework/checkpoint-data.cpp | 4 +- tests/framework/comm-mpi.cpp | 70 +++++++++---------- tests/framework/comm-nompi.cpp | 29 ++++---- tests/framework/fields.cpp | 2 +- tests/framework/grid_mesh.cpp | 2 +- tests/framework/metadomain.cpp | 2 +- tests/framework/parameters.cpp | 2 +- tests/framework/particles.cpp | 2 +- tests/framework/particles_sort.cpp | 4 +- tests/global/global.cpp | 8 ++- tests/global/kokkos_aliases.cpp | 2 +- tests/global/sorting.cpp | 2 +- tests/global/tiling.cpp | 18 ++--- tests/global/traits_pgen.cpp | 2 +- tests/global/traits_policies.cpp | 4 +- tests/kernels/ampere_mink.cpp | 58 +++++++-------- tests/kernels/custom_prtl_update.cpp | 30 ++++---- tests/kernels/deposit.cpp | 2 +- tests/kernels/digital_filter.cpp | 14 ++-- tests/kernels/ext_force.cpp | 6 +- tests/kernels/faraday_mink.cpp | 59 ++++++++-------- tests/kernels/fields_to_phys.cpp | 6 +- tests/kernels/flds_bc.cpp | 10 +-- tests/kernels/gca_pusher.cpp | 6 +- tests/kernels/particle_moments.cpp | 6 +- tests/kernels/prtl_bc.cpp | 30 ++++---- tests/kernels/prtls_to_phys.cpp | 18 ++--- tests/kernels/pusher.cpp | 6 +- tests/kernels/reduced_stats.cpp | 12 ++-- tests/metrics/coord_trans.cpp | 30 ++++---- tests/metrics/ks-qks.cpp | 20 +++--- tests/metrics/minkowski.cpp | 4 +- tests/metrics/sph-qsph.cpp | 22 +++--- tests/metrics/sr-cart-sph.cpp | 22 +++--- tests/metrics/vec_trans.cpp | 28 ++++---- tests/output/fields.cpp | 2 +- tests/output/stats.cpp | 2 +- tests/output/writer-mpi.cpp | 8 +-- tests/output/writer-nompi.cpp | 8 +-- 102 files changed, 681 insertions(+), 639 deletions(-) diff --git a/pgens/examples/custom_particle_update/pgen.hpp b/pgens/examples/custom_particle_update/pgen.hpp index 067dcdd4d..30e464099 100644 --- a/pgens/examples/custom_particle_update/pgen.hpp +++ b/pgens/examples/custom_particle_update/pgen.hpp @@ -136,7 +136,7 @@ namespace user { , xmin { xmin } , xmax { xmax } {} - Inline void operator()(index_t p, + Inline void operator()(prtlidx_t p, const kernel::sr::PusherContext& ctx, const kernel::sr::PusherBoundaries&, const ntt::ParticleArrays& particles, diff --git a/pgens/examples/piston/pgen.hpp b/pgens/examples/piston/pgen.hpp index bcabfaa03..9274374e2 100644 --- a/pgens/examples/piston/pgen.hpp +++ b/pgens/examples/piston/pgen.hpp @@ -79,7 +79,7 @@ namespace user { bool is_left; bool massive; - Inline void operator()(index_t p, + Inline void operator()(prtlidx_t p, const kernel::sr::PusherContext& ctx, const kernel::sr::PusherBoundaries&, const ParticleArrays& particles, diff --git a/pgens/examples/tutorial_cartesian_sr/pgen.hpp b/pgens/examples/tutorial_cartesian_sr/pgen.hpp index daa488909..2dc7e5f6e 100644 --- a/pgens/examples/tutorial_cartesian_sr/pgen.hpp +++ b/pgens/examples/tutorial_cartesian_sr/pgen.hpp @@ -54,7 +54,7 @@ namespace user { template Inline auto GetParticlePosition(const M& metric, - index_t p, + prtlidx_t p, const array_t& i1, const array_t& dx1, const array_t& i2, @@ -77,7 +77,7 @@ namespace user { } template - Inline void SetParticleSpeed(index_t p, + Inline void SetParticleSpeed(prtlidx_t p, const array_t& ux1, const array_t& ux2, const array_t& ux3, @@ -188,7 +188,7 @@ namespace user { Kokkos::parallel_for( "PurgeParticles", species.rangeActiveParticles(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { if (tag(p) != ParticleTag::alive) { return; } diff --git a/pgens/shock/pgen.hpp b/pgens/shock/pgen.hpp index 39f6baf99..7a7aaac21 100644 --- a/pgens/shock/pgen.hpp +++ b/pgens/shock/pgen.hpp @@ -247,7 +247,7 @@ namespace user { } const auto extent = domain.mesh.ExtentToRange(purge_box, incl_ghosts); - tuple_t x_min { 0 }, x_max { 0 }; + tuple_t x_min { 0 }, x_max { 0 }; for (auto d = 0; d < M::Dim; ++d) { x_min[d] = extent[d].first; x_max[d] = extent[d].second; @@ -277,7 +277,7 @@ namespace user { Kokkos::parallel_for( "RemoveParticles", species.rangeActiveParticles(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { // check if the particle is already dead if (tag(p) == ParticleTag::dead) { return; diff --git a/pgens/turbulence/pgen.hpp b/pgens/turbulence/pgen.hpp index 706c603da..45b802c64 100644 --- a/pgens/turbulence/pgen.hpp +++ b/pgens/turbulence/pgen.hpp @@ -359,7 +359,7 @@ namespace user { Kokkos::parallel_for( "Antenna amplitudes", wavenumbers.size(), - ClassLambda(index_t i) { + ClassLambda(cellidx_t i) { auto generator = random_pool.get_state(); const auto u_imag = Random(generator) - HALF; const auto u_real = Random(generator) - HALF; @@ -415,7 +415,7 @@ namespace user { Kokkos::parallel_for( "UpdatePld", domain.species[sp].npart(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { if (tag(p) == ParticleTag::dead) { return; } diff --git a/src/archetypes/field_setter.h b/src/archetypes/field_setter.h index be3015a2f..1e3137d01 100644 --- a/src/archetypes/field_setter.h +++ b/src/archetypes/field_setter.h @@ -60,7 +60,7 @@ namespace arch { ~SetEMFields_kernel() = default; - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { const auto i1_ = COORD(i1); coord_t x_Phys { ZERO }; @@ -109,7 +109,7 @@ namespace arch { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); @@ -197,7 +197,7 @@ namespace arch { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); @@ -317,7 +317,7 @@ namespace arch { , fields { fields } , fieldsetter { fieldsetter } {} - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { const auto i1_ = COORD(i1); coord_t x_Ph { ZERO }; @@ -417,7 +417,7 @@ namespace arch { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); @@ -557,7 +557,7 @@ namespace arch { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); diff --git a/src/archetypes/moving_window.h b/src/archetypes/moving_window.h index b4ef21558..42fd8f9ca 100644 --- a/src/archetypes/moving_window.h +++ b/src/archetypes/moving_window.h @@ -37,7 +37,7 @@ namespace arch { , window_shift { window_shift } , tags { tags } {} - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { if (tags & BC::E) { Fld(i1, em::ex1) = backup_Fld(i1 + window_shift, em::ex1); @@ -56,7 +56,7 @@ namespace arch { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { if constexpr (o == in::x1) { if (tags & BC::E) { @@ -88,7 +88,7 @@ namespace arch { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { if constexpr (o == in::x1) { if (tags & BC::E) { @@ -155,7 +155,7 @@ namespace arch { Kokkos::parallel_for( "MoveParticles", species.rangeActiveParticles(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { // shift particle position back by window update frequency i1(p) -= window_shift; }); @@ -170,7 +170,7 @@ namespace arch { Kokkos::parallel_for( "MoveParticles", species.rangeActiveParticles(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { // shift particle position back by window update frequency i2(p) -= window_shift; }); @@ -188,7 +188,7 @@ namespace arch { Kokkos::parallel_for( "MoveParticles", species.rangeActiveParticles(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { // shift particle position back by window update frequency i3(p) -= window_shift; }); @@ -201,8 +201,8 @@ namespace arch { } // shift fields in the window back by the window size - std::vector xi_min, xi_max; - const std::vector all_dirs { in::x1, in::x2, in::x3 }; + std::vector xi_min, xi_max; + const std::vector all_dirs { in::x1, in::x2, in::x3 }; for (auto d { 0u }; d < M::Dim; ++d) { const auto dd = all_dirs[d]; if (o == dd) { diff --git a/src/archetypes/piston.h b/src/archetypes/piston.h index 57d7becbb..66f7160f2 100644 --- a/src/archetypes/piston.h +++ b/src/archetypes/piston.h @@ -49,7 +49,7 @@ namespace arch { * @param is_left Is piston on the left side of the box or right side of the box */ template - Inline bool CrossesPiston(index_t p, + Inline bool CrossesPiston(prtlidx_t p, real_t dt, const ntt::ParticleArrays& particles, const M& metric, @@ -82,7 +82,7 @@ namespace arch { * @param massive Whether the particle is massive or massless (e.g. photon) */ template - Inline void Piston(index_t p, + Inline void Piston(prtlidx_t p, real_t dt, const ntt::ParticleArrays& particles, const M& metric, diff --git a/src/engines/engine.hpp b/src/engines/engine.hpp index 8d54a5ec3..b20e163ca 100644 --- a/src/engines/engine.hpp +++ b/src/engines/engine.hpp @@ -292,7 +292,7 @@ namespace ntt { ::traits::pgen::HasCustomFieldOutput>) { auto lambda_custom_field_output = [&](const std::string& name, ndfield_t& buff, - index_t idx, + cellidx_t idx, timestep_t step, simtime_t time, const Domain& dom) { diff --git a/src/engines/grpic/currents.h b/src/engines/grpic/currents.h index 2aed0843f..11c847533 100644 --- a/src/engines/grpic/currents.h +++ b/src/engines/grpic/currents.h @@ -82,7 +82,7 @@ namespace ntt { { domain.mesh.i_max(in::x1), domain.mesh.i_max(in::x2) + 1 }); const auto nfilter = params.template get( "algorithms.current_filters"); - tuple_t size; + tuple_t size; size[0] = domain.mesh.n_active(in::x1); size[1] = domain.mesh.n_active(in::x2); diff --git a/src/engines/grpic/fields_bcs.h b/src/engines/grpic/fields_bcs.h index 6520769f4..3297a17df 100644 --- a/src/engines/grpic/fields_bcs.h +++ b/src/engines/grpic/fields_bcs.h @@ -86,8 +86,8 @@ namespace ntt { return; } const auto intersect_range = domain.mesh.ExtentToRange(box, incl_ghosts); - tuple_t range_min { 0 }; - tuple_t range_max { 0 }; + tuple_t range_min { 0 }; + tuple_t range_max { 0 }; for (unsigned short d { 0 }; d < M::Dim; ++d) { range_min[d] = intersect_range[d].first; diff --git a/src/engines/grpic/grpic.hpp b/src/engines/grpic/grpic.hpp index cf7d19cf1..fc2daa4de 100644 --- a/src/engines/grpic/grpic.hpp +++ b/src/engines/grpic/grpic.hpp @@ -68,7 +68,7 @@ namespace ntt { "algorithms.fieldsolver.enable"); const auto deposit_enabled = m_params.template get( "algorithms.deposit.enable"); - const auto clear_interval = m_params.template get( + const auto clear_interval = m_params.template get( "particles.clear_interval"); if (step == 0) { diff --git a/src/engines/srpic/fields_bcs.h b/src/engines/srpic/fields_bcs.h index 7552dc5e3..97c16f866 100644 --- a/src/engines/srpic/fields_bcs.h +++ b/src/engines/srpic/fields_bcs.h @@ -366,7 +366,7 @@ namespace ntt { const auto sign = direction.get_sign(); const auto dim = direction.get_dim(); - std::vector xi_min, xi_max; + std::vector xi_min, xi_max; const std::vector all_dirs { in::x1, in::x2, in::x3 }; @@ -397,7 +397,7 @@ namespace ntt { } else { raise::Error("Invalid dimension", HERE); } - std::size_t i_edge; + ncells_t i_edge; if (sign > 0) { i_edge = domain.mesh.i_max(dim); } else { @@ -509,15 +509,15 @@ namespace ntt { return; } const auto intersect_range = domain.mesh.ExtentToRange(box, incl_ghosts); - tuple_t range_min { 0 }; - tuple_t range_max { 0 }; + tuple_t range_min { 0 }; + tuple_t range_max { 0 }; for (auto d { 0u }; d < M::Dim; ++d) { range_min[d] = intersect_range[d].first; range_max[d] = intersect_range[d].second; } - auto atm_fields = pgen.AtmFields(time); - std::size_t il_edge; + auto atm_fields = pgen.AtmFields(time); + ncells_t il_edge; if (sign > 0) { il_edge = range_min[dd] - N_GHOSTS; } else { diff --git a/src/framework/containers/fields_io.cpp b/src/framework/containers/fields_io.cpp index 9cf5f8806..683519493 100644 --- a/src/framework/containers/fields_io.cpp +++ b/src/framework/containers/fields_io.cpp @@ -9,6 +9,7 @@ #include +#include #include namespace ntt { @@ -21,9 +22,9 @@ namespace ntt { const std::vector& local_offset) const { logger::Checkpoint("Declaring fields checkpoint", HERE); - auto gs6 = std::vector(global_shape.begin(), global_shape.end()); - auto lo6 = std::vector(local_offset.begin(), local_offset.end()); - auto ls6 = std::vector(local_shape.begin(), local_shape.end()); + auto gs6 = std::vector(global_shape.begin(), global_shape.end()); + auto lo6 = std::vector(local_offset.begin(), local_offset.end()); + auto ls6 = std::vector(local_shape.begin(), local_shape.end()); gs6.push_back(6); lo6.push_back(0); ls6.push_back(6); @@ -31,9 +32,9 @@ namespace ntt { io.DefineVariable("em", gs6, lo6, ls6); if (S == ntt::SimEngine::GRPIC) { io.DefineVariable("em0", gs6, lo6, ls6); - auto gs3 = std::vector(global_shape.begin(), global_shape.end()); - auto lo3 = std::vector(local_offset.begin(), local_offset.end()); - auto ls3 = std::vector(local_shape.begin(), local_shape.end()); + auto gs3 = std::vector(global_shape.begin(), global_shape.end()); + auto lo3 = std::vector(local_offset.begin(), local_offset.end()); + auto ls3 = std::vector(local_shape.begin(), local_shape.end()); gs3.push_back(3); lo3.push_back(0); ls3.push_back(3); diff --git a/src/framework/containers/particles.h b/src/framework/containers/particles.h index 2f0a88856..41d96db9a 100644 --- a/src/framework/containers/particles.h +++ b/src/framework/containers/particles.h @@ -85,9 +85,9 @@ namespace ntt { bool m_is_sorted { false }; #if !defined(MPI_ENABLED) - const std::size_t m_ntags { 2 }; + const uint8_t m_ntags { 2u }; #else // MPI_ENABLED - const std::size_t m_ntags { (std::size_t)(2 + math::pow(3, (int)D) - 1) }; + const uint8_t m_ntags { (uint8_t)(2 + math::pow(3, (int)D) - 1) }; #endif public: @@ -154,7 +154,7 @@ namespace ntt { * @returns A 1D Kokkos range policy of size of `npart` */ auto rangeActiveParticles() const -> range_t { - return CreateParticleRangePolicy(0u, npart()); + return CreateParticleRangePolicy({ 0u }, { npart() }); } /** @@ -162,7 +162,7 @@ namespace ntt { * @returns A 1D Kokkos range policy of size of `npart` */ auto rangeAllParticles() const -> range_t { - return CreateParticleRangePolicy(0u, maxnpart()); + return CreateParticleRangePolicy({ 0u }, { maxnpart() }); } /* getters -------------------------------------------------------------- */ @@ -194,7 +194,7 @@ namespace ntt { * @brief Get the number of distinct tags possible */ [[nodiscard]] - auto ntags() const -> std::size_t { + auto ntags() const -> uint8_t { return m_ntags; } diff --git a/src/framework/containers/particles_io.cpp b/src/framework/containers/particles_io.cpp index 47b3cb3f8..759e3985d 100644 --- a/src/framework/containers/particles_io.cpp +++ b/src/framework/containers/particles_io.cpp @@ -108,7 +108,7 @@ namespace ntt { Kokkos::parallel_reduce( "CountOutputParticles", rangeActiveParticles(), - Lambda(index_t p, npart_t & l_nout) { + Lambda(prtlidx_t p, npart_t & l_nout) { if ((tag_d(p) == ParticleTag::alive) and (pld_i_d(p, pldi::spcCtr) % prtl_stride == 0)) { l_nout += 1; @@ -120,7 +120,7 @@ namespace ntt { Kokkos::parallel_for( "RecordOutputIndices", rangeActiveParticles(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { if ((tag_d(p) == ParticleTag::alive) and (pld_i_d(p, pldi::spcCtr) % prtl_stride == 0)) { const auto p_out = Kokkos::atomic_fetch_add(&out_counter(), 1); diff --git a/src/framework/containers/particles_sort.cpp b/src/framework/containers/particles_sort.cpp index 2fd94628b..8741c966a 100644 --- a/src/framework/containers/particles_sort.cpp +++ b/src/framework/containers/particles_sort.cpp @@ -30,7 +30,7 @@ namespace ntt { Kokkos::parallel_for( "NpartPerTag", rangeActiveParticles(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { auto npptag_acc = npptag_scat.access(); if (this_tag(p) < 0 || this_tag(p) >= static_cast(num_tags)) { raise::KernelError(HERE, "Invalid tag value"); @@ -67,7 +67,7 @@ namespace ntt { Kokkos::parallel_for( "PopulateBufferAlive", n_alive, - Lambda(index_t p) { buffer(p) = arr(indices_alive(p)); }); + Lambda(prtlidx_t p) { buffer(p) = arr(indices_alive(p)); }); Kokkos::deep_copy( Kokkos::subview(arr, std::make_pair(static_cast(0), n_alive)), @@ -80,8 +80,12 @@ namespace ntt { auto buffer = array_t { "buffer", n_alive, arr.extent(1) }; Kokkos::parallel_for( "PopulateBufferAlive", - CreateRangePolicy({ 0, 0 }, { n_alive, arr.extent(1) }), - Lambda(index_t p, index_t l) { buffer(p, l) = arr(indices_alive(p), l); }); + CreateParticleRangePolicy( + { 0, 0 }, + { n_alive, static_cast(arr.extent(1)) }), + Lambda(prtlidx_t p, prtlidx_t l) { + buffer(p, l) = arr(indices_alive(p), l); + }); Kokkos::deep_copy( Kokkos::subview(arr, @@ -98,7 +102,7 @@ namespace ntt { Kokkos::parallel_reduce( "CountDeadAlive", rangeActiveParticles(), - Lambda(index_t p, npart_t & nalive, npart_t & ndead) { + Lambda(prtlidx_t p, npart_t & nalive, npart_t & ndead) { nalive += (this_tag(p) == ParticleTag::alive); ndead += (this_tag(p) == ParticleTag::dead); if (this_tag(p) != ParticleTag::alive and this_tag(p) != ParticleTag::dead) { @@ -114,7 +118,7 @@ namespace ntt { Kokkos::parallel_for( "AliveIndices", rangeActiveParticles(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { if (this_tag(p) == ParticleTag::alive) { const auto idx = Kokkos::atomic_fetch_add(&alive_counter(0), 1); indices_alive(idx) = p; @@ -199,7 +203,7 @@ namespace ntt { tag, cell_indices, grid.n_active() }); - const auto slice = range_tuple_t(0, npart()); + const auto slice = prtl_slice_t(0, npart()); using sorter_op_t = Kokkos::BinOp1D; using sorter_t = Kokkos::BinSort; diff --git a/src/framework/domain/comm_mpi.hpp b/src/framework/domain/comm_mpi.hpp index 266c844c5..e3598f8b0 100644 --- a/src/framework/domain/comm_mpi.hpp +++ b/src/framework/domain/comm_mpi.hpp @@ -124,17 +124,17 @@ namespace comm { } // namespace flds template - inline void CommunicateField(unsigned int idx, - ndfield_t& fld, - ndfield_t& fld_buff, - unsigned int send_idx, - unsigned int recv_idx, - int send_rank, - int recv_rank, - const std::vector& send_slice, - const std::vector& recv_slice, - const range_tuple_t& comps, - bool additive) { + inline void CommunicateField(unsigned int idx, + ndfield_t& fld, + ndfield_t& fld_buff, + unsigned int send_idx, + unsigned int recv_idx, + int send_rank, + int recv_rank, + const std::vector& send_slice, + const std::vector& recv_slice, + const cell_range_t& comps, + bool additive) { raise::ErrorIf(send_rank < 0 && recv_rank < 0, "CommunicateField called with negative ranks", HERE); @@ -176,7 +176,7 @@ namespace comm { Kokkos::MDRangePolicy, Kokkos::DefaultExecutionSpace>( { recv_slice[0].first, comps.first }, { recv_slice[0].second, comps.second }), - Lambda(index_t i1, index_t ci) { + Lambda(cellidx_t i1, cellidx_t ci) { fld_buff(i1, ci) += fld(i1 - offset_x1, ci); }); } else if constexpr (D == Dim::_2D) { @@ -189,7 +189,7 @@ namespace comm { Kokkos::MDRangePolicy, Kokkos::DefaultExecutionSpace>( { recv_slice[0].first, recv_slice[1].first, comps.first }, { recv_slice[0].second, recv_slice[1].second, comps.second }), - Lambda(index_t i1, index_t i2, index_t ci) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t ci) { fld_buff(i1, i2, ci) += fld(i1 - offset_x1, i2 - offset_x2, ci); }); } else if constexpr (D == Dim::_3D) { @@ -210,7 +210,7 @@ namespace comm { recv_slice[1].second, recv_slice[2].second, comps.second }), - Lambda(index_t i1, index_t i2, index_t i3, index_t ci) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3, cellidx_t ci) { fld_buff(i1, i2, i3, ci) += fld(i1 - offset_x1, i2 - offset_x2, i3 - offset_x3, @@ -305,7 +305,7 @@ namespace comm { Kokkos::MDRangePolicy, Kokkos::DefaultExecutionSpace>( { recv_slice[0].first, comps.first }, { recv_slice[0].second, comps.second }), - Lambda(index_t i1, index_t ci) { + Lambda(cellidx_t i1, cellidx_t ci) { fld_buff(i1, ci) += recv_fld(i1 - offset_x1, ci - offset_c); }); } else if constexpr (D == Dim::_2D) { @@ -317,7 +317,7 @@ namespace comm { Kokkos::MDRangePolicy, Kokkos::DefaultExecutionSpace>( { recv_slice[0].first, recv_slice[1].first, comps.first }, { recv_slice[0].second, recv_slice[1].second, comps.second }), - Lambda(index_t i1, index_t i2, index_t ci) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t ci) { fld_buff(i1, i2, ci) += recv_fld(i1 - offset_x1, i2 - offset_x2, ci - offset_c); @@ -338,7 +338,7 @@ namespace comm { recv_slice[1].second, recv_slice[2].second, comps.second }), - Lambda(index_t i1, index_t i2, index_t i3, index_t ci) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3, cellidx_t ci) { fld_buff(i1, i2, i3, ci) += recv_fld(i1 - offset_x1, i2 - offset_x2, i3 - offset_x3, diff --git a/src/framework/domain/comm_nompi.hpp b/src/framework/domain/comm_nompi.hpp index d0cc36cbd..16e20d261 100644 --- a/src/framework/domain/comm_nompi.hpp +++ b/src/framework/domain/comm_nompi.hpp @@ -26,17 +26,17 @@ namespace comm { * @note: `fld` and `fld_buff` may be the same */ template - inline void CommunicateField(unsigned int idx, - ndfield_t& fld, - ndfield_t& fld_buff, - unsigned int send_idx, - unsigned int recv_idx, - int send_rank, - int recv_rank, - const std::vector& send_slice, - const std::vector& recv_slice, - const range_tuple_t& comps, - bool additive) { + inline void CommunicateField(unsigned int idx, + ndfield_t& fld, + ndfield_t& fld_buff, + unsigned int send_idx, + unsigned int recv_idx, + int send_rank, + int recv_rank, + const std::vector& send_slice, + const std::vector& recv_slice, + const cell_range_t& comps, + bool additive) { raise::ErrorIf(send_rank < 0 && recv_rank < 0, "CommunicateField called with negative ranks", HERE); @@ -71,7 +71,7 @@ namespace comm { Kokkos::MDRangePolicy, Kokkos::DefaultExecutionSpace>( { recv_slice[0].first, comps.first }, { recv_slice[0].second, comps.second }), - Lambda(index_t i1, index_t ci) { + Lambda(cellidx_t i1, cellidx_t ci) { fld_buff(i1, ci) += fld(i1 - offset_x1, ci); }); } else if constexpr (D == Dim::_2D) { @@ -84,7 +84,7 @@ namespace comm { Kokkos::MDRangePolicy, Kokkos::DefaultExecutionSpace>( { recv_slice[0].first, recv_slice[1].first, comps.first }, { recv_slice[0].second, recv_slice[1].second, comps.second }), - Lambda(index_t i1, index_t i2, index_t ci) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t ci) { fld_buff(i1, i2, ci) += fld(i1 - offset_x1, i2 - offset_x2, ci); }); } else if constexpr (D == Dim::_3D) { @@ -105,7 +105,7 @@ namespace comm { recv_slice[1].second, recv_slice[2].second, comps.second }), - Lambda(index_t i1, index_t i2, index_t i3, index_t ci) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3, cellidx_t ci) { fld_buff(i1, i2, i3, ci) += fld(i1 - offset_x1, i2 - offset_x2, i3 - offset_x3, diff --git a/src/framework/domain/metadomain.h b/src/framework/domain/metadomain.h index c0a11efa2..2ff5fe40f 100644 --- a/src/framework/domain/metadomain.h +++ b/src/framework/domain/metadomain.h @@ -95,7 +95,7 @@ namespace ntt { void CommunicateFields(Domain&, CommTags) const; void SynchronizeFields(Domain&, CommTags, - const range_tuple_t& = { 0, 0 }) const; + const cell_range_t& = { 0, 0 }) const; #if defined(MPI_ENABLED) && defined(OUTPUT_ENABLED) void CommunicateVectorPotential(unsigned short); #endif @@ -143,7 +143,7 @@ namespace ntt { simtime_t, const std::function&, - index_t, + uint32_t, timestep_t, simtime_t, const Domain&)>& = nullptr) -> bool; diff --git a/src/framework/domain/metadomain_chckpt.cpp b/src/framework/domain/metadomain_chckpt.cpp index e4622f92a..06918a053 100644 --- a/src/framework/domain/metadomain_chckpt.cpp +++ b/src/framework/domain/metadomain_chckpt.cpp @@ -17,6 +17,7 @@ #include #endif +#include #include #include #include @@ -178,21 +179,20 @@ namespace ntt { for (const auto& n : ncells_at_pos) { total += n; } - raise::ErrorIf( - total != g_mesh.n_active()[d], - fmt::format( - "total cells in dim %d changed between checkpoint (%lu) and current (%lu); " - "changing total domain size is not supported", - d + 1, - total, - g_mesh.n_active()[d]), - HERE); + raise::ErrorIf(total != g_mesh.n_active()[d], + fmt::format("total cells in dim %d changed between " + "checkpoint (%lu) and current (%lu); " + "changing total domain size is not supported", + d + 1, + total, + g_mesh.n_active()[d]), + HERE); ncells_t running { 0 }; std::vector offset_at_pos(g_ndomains_per_dim[d], 0); for (unsigned int nd { 0 }; nd < g_ndomains_per_dim[d]; ++nd) { - offset_at_pos[nd] = running; - running += ncells_at_pos[nd]; + offset_at_pos[nd] = running; + running += ncells_at_pos[nd]; } for (unsigned int idx { 0 }; idx < g_ndomains; ++idx) { offset_ncells_per_dom[idx][d] = offset_at_pos[g_domain_offsets[idx][d]]; @@ -268,12 +268,12 @@ namespace ntt { // Phase 1: read all subdomain metadata to detect size changes std::vector> saved_ncells(g_ndomains, - std::vector(M::Dim)); + std::vector(M::Dim)); std::vector> saved_extents(g_ndomains); boundaries_t global_extent; for (auto d { 0u }; d < M::Dim; ++d) { global_extent.emplace_back(std::numeric_limits::max(), - std::numeric_limits::lowest()); + std::numeric_limits::lowest()); } bool needs_reconstruction = false; diff --git a/src/framework/domain/metadomain_comm.cpp b/src/framework/domain/metadomain_comm.cpp index ee7803182..e492752c4 100644 --- a/src/framework/domain/metadomain_comm.cpp +++ b/src/framework/domain/metadomain_comm.cpp @@ -30,7 +30,7 @@ namespace ntt { using address_t = std::pair; - using comm_params_t = std::pair>; + using comm_params_t = std::pair>; template auto GetSendRecvRanks(const Metadomain* const metadomain, @@ -133,8 +133,8 @@ namespace ntt { { { 0, -1 }, {} } }; } - auto send_slice = std::vector {}; - auto recv_slice = std::vector {}; + auto send_slice = std::vector {}; + auto recv_slice = std::vector {}; const in components[] = { in::x1, in::x2, in::x3 }; // find the field components and indices to be sent/received for (auto d { 0u }; d < direction.size(); ++d) { @@ -246,31 +246,31 @@ namespace ntt { * on a single rank, however that is not yet implemented */ // establish the last index ranges for fields (i.e., components) - auto comp_range_fld = range_tuple_t {}; - auto comp_range_cur = range_tuple_t {}; + auto comp_range_fld = cell_range_t {}; + auto comp_range_cur = cell_range_t {}; if constexpr (S == SimEngine::GRPIC) { if (((tags & Comm::D) and (tags & Comm::B)) or ((tags & Comm::D0) and (tags & Comm::B0)) or ((tags & Comm::E) and (tags & Comm::H))) { - comp_range_fld = range_tuple_t(em::dx1, em::bx3 + 1); + comp_range_fld = cell_range_t(em::dx1, em::bx3 + 1); } else if ((tags & Comm::D) or (tags & Comm::D0) or (tags & Comm::E)) { - comp_range_fld = range_tuple_t(em::dx1, em::dx3 + 1); + comp_range_fld = cell_range_t(em::dx1, em::dx3 + 1); } else if ((tags & Comm::B) or (tags & Comm::B0) or (tags & Comm::H)) { - comp_range_fld = range_tuple_t(em::bx1, em::bx3 + 1); + comp_range_fld = cell_range_t(em::bx1, em::bx3 + 1); } } else if constexpr (S == SimEngine::SRPIC) { if ((tags & Comm::E) and (tags & Comm::B)) { - comp_range_fld = range_tuple_t(em::ex1, em::bx3 + 1); + comp_range_fld = cell_range_t(em::ex1, em::bx3 + 1); } else if (tags & Comm::E) { - comp_range_fld = range_tuple_t(em::ex1, em::ex3 + 1); + comp_range_fld = cell_range_t(em::ex1, em::ex3 + 1); } else if (tags & Comm::B) { - comp_range_fld = range_tuple_t(em::bx1, em::bx3 + 1); + comp_range_fld = cell_range_t(em::bx1, em::bx3 + 1); } } else { raise::Error("Unknown simulation engine", HERE); } if (comm_j) { - comp_range_cur = range_tuple_t(cur::jx1, cur::jx3 + 1); + comp_range_cur = cell_range_t(cur::jx1, cur::jx3 + 1); } // traverse in all directions and send/recv the fields for (auto& direction : dir::Directions::all) { @@ -380,17 +380,17 @@ namespace ntt { } template - void AddBufferedFields(ndfield_t& field, - ndfield_t& buffer, - const range_t& range_policy, - const range_tuple_t& components) { + void AddBufferedFields(ndfield_t& field, + ndfield_t& buffer, + const range_t& range_policy, + const cell_range_t& components) { const auto cmin = components.first; const auto cmax = components.second; if constexpr (D == Dim::_1D) { Kokkos::parallel_for( "AddBufferedFields", range_policy, - Lambda(index_t i1) { + Lambda(cellidx_t i1) { for (auto c { cmin }; c < cmax; ++c) { field(i1, c) += buffer(i1, c); } @@ -399,7 +399,7 @@ namespace ntt { Kokkos::parallel_for( "AddBufferedFields", range_policy, - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { for (auto c { cmin }; c < cmax; ++c) { field(i1, i2, c) += buffer(i1, i2, c); } @@ -408,7 +408,7 @@ namespace ntt { Kokkos::parallel_for( "AddBuffers", range_policy, - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { for (auto c { cmin }; c < cmax; ++c) { field(i1, i2, i3, c) += buffer(i1, i2, i3, c); } @@ -421,7 +421,7 @@ namespace ntt { template void Metadomain::SynchronizeFields(Domain& domain, CommTags tags, - const range_tuple_t& components) const { + const cell_range_t& components) const { const bool comm_j = (tags & Comm::J); const bool comm_bckp = (tags & Comm::Bckp); const bool comm_buff = (tags & Comm::Buff); @@ -445,9 +445,9 @@ namespace ntt { } logger::Checkpoint(fmt::format("Synchronizing %s\n", comms.c_str()), HERE); - auto comp_range_cur = range_tuple_t {}; + auto comp_range_cur = cell_range_t {}; if (comm_j) { - comp_range_cur = range_tuple_t(cur::jx1, cur::jx3 + 1); + comp_range_cur = cell_range_t(cur::jx1, cur::jx3 + 1); Kokkos::deep_copy(domain.fields.buff, ZERO); } ndfield_t bckp_recv; @@ -666,13 +666,12 @@ namespace ntt { } // NOLINTBEGIN(bugprone-macro-parentheses) -#define METADOMAIN_COMM(S, M, D) \ - template void Metadomain>::CommunicateFields(Domain>&, \ - CommTags) const; \ - template void Metadomain>::SynchronizeFields(Domain>&, \ - CommTags, \ - const range_tuple_t&) \ - const; \ +#define METADOMAIN_COMM(S, M, D) \ + template void Metadomain>::CommunicateFields(Domain>&, \ + CommTags) const; \ + template void Metadomain>::SynchronizeFields(Domain>&, \ + CommTags, \ + const cell_range_t&) const; \ template void Metadomain>::CommunicateParticles(Domain>&) const; NTT_FOREACH_SPECIALIZATION(METADOMAIN_COMM) diff --git a/src/framework/domain/metadomain_io.cpp b/src/framework/domain/metadomain_io.cpp index 2f2c84972..acae97166 100644 --- a/src/framework/domain/metadomain_io.cpp +++ b/src/framework/domain/metadomain_io.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -162,10 +163,10 @@ namespace ntt { } template - void DeepCopyFields(ndfield_t& fld_from, - ndfield_t& fld_to, - const range_tuple_t& from, - const range_tuple_t& to) { + void DeepCopyFields(ndfield_t& fld_from, + ndfield_t& fld_to, + const cell_range_t& from, + const cell_range_t& to) { for (auto d { 0u }; d < D; ++d) { raise::ErrorIf(fld_from.extent(d) != fld_to.extent(d), "Fields have different sizes " + @@ -196,7 +197,7 @@ namespace ntt { Kokkos::parallel_for( "ComputeVectorPotential", mesh.rangeActiveCells(), - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { const real_t i1_ { COORD(i1) }; const ncells_t k_min = 0; const ncells_t k_max = (i2 - (N_GHOSTS)); @@ -224,10 +225,10 @@ namespace ntt { // "ComputeVectorPotential", // policy, // Lambda(const TeamPolicy::member_type& team_member) { - // index_t i1 = team_member.league_rank(); + // cellidx_t i1 = team_member.league_rank(); // Kokkos::parallel_scan( // Kokkos::TeamThreadRange(team_member, nx2), - // [=](index_t i2, real_t& update, const bool final_pass) { + // [=](cellidx_t i2, real_t& update, const bool final_pass) { // const auto i1_ { static_cast(i1) }; // const auto i2_ { static_cast(i2) }; // const real_t sqrt_detH_ijM { metric.sqrt_det_h({ i1_, i2_ - HALF }) }; @@ -258,7 +259,7 @@ namespace ntt { Kokkos::parallel_for( "AddVectorPotential", mesh.rangeActiveCells(), - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { buffer(i1, i2, buff_idx) += aphi_r(i1 - N_GHOSTS); }); } @@ -326,7 +327,7 @@ namespace ntt { simtime_t finished_time, const std::function&, - index_t, + uint32_t, timestep_t, simtime_t, const Domain&)>& CustomFieldOutput) -> bool { @@ -407,7 +408,7 @@ namespace ntt { Kokkos::parallel_for( "GenerateMesh", ncells, - Lambda(index_t i_dwn) { + Lambda(cellidx_t i_dwn) { const auto i = first_cell + i_dwn * dwn_in_dim; const auto i_ = static_cast(i); coord_t x_Cd { ZERO }, x_Ph { ZERO }; @@ -435,7 +436,7 @@ namespace ntt { for (auto& fld : g_writer.fieldWriters()) { Kokkos::deep_copy(local_domain->fields.bckp, ZERO); std::vector names; - std::vector addresses; + std::vector addresses; if (fld.comp.empty() || fld.comp.size() == 1) { // scalar names.push_back(fld.name()); addresses.push_back(0); @@ -616,7 +617,7 @@ namespace ntt { } else { // copy fields to bckp (:, 0, 1, 2) // if as-is specified ==> copy directly to 3, 4, 5 - range_tuple_t copy_to = { 0, 3 }; + cell_range_t copy_to = { 0, 3 }; if (output_asis) { copy_to = { 3, 6 }; } @@ -661,8 +662,8 @@ namespace ntt { if (not output_asis) { // copy fields from bckp(:, 0, 1, 2) -> bckp(:, 3, 4, 5) // converting to proper basis and properly interpolating - list_t comp_from = { 0, 1, 2 }; - list_t comp_to = { 3, 4, 5 }; + list_t comp_from = { 0, 1, 2 }; + list_t comp_to = { 3, 4, 5 }; DeepCopyFields(local_domain->fields.bckp, local_domain->fields.bckp, { 0, 3 }, @@ -740,7 +741,7 @@ namespace ntt { Kokkos::parallel_for( "GenerateEnergyBins", n_bins + 1, - Lambda(index_t e) { + Lambda(uint32_t e) { if (log_bins) { energy(e) = math::pow(static_cast(10), e_min + (e_max - e_min) * static_cast(e) / @@ -763,7 +764,7 @@ namespace ntt { Kokkos::parallel_for( "ComputeSpectra", species.rangeActiveParticles(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { if (tag(p) != ParticleTag::alive) { return; } @@ -810,7 +811,7 @@ namespace ntt { simtime_t, \ const std::function::Dim, 6>&, \ - index_t, \ + uint32_t, \ timestep_t, \ simtime_t, \ const Domain>&)>&) -> bool; diff --git a/src/global/arch/kokkos_aliases.cpp b/src/global/arch/kokkos_aliases.cpp index 25397af8e..211b63471 100644 --- a/src/global/arch/kokkos_aliases.cpp +++ b/src/global/arch/kokkos_aliases.cpp @@ -4,16 +4,34 @@ #include -auto CreateParticleRangePolicy(npart_t p1, npart_t p2) -> range_t { - return Kokkos::RangePolicy(p1, p2); +template <> +auto CreateParticleRangePolicy(const tuple_t& p1, + const tuple_t& p2) + -> range_t { + prtlidx_t p1min = p1[0]; + prtlidx_t p1max = p2[0]; + return Kokkos::RangePolicy(p1min, p1max); +} + +template <> +auto CreateParticleRangePolicy(const tuple_t& p1, + const tuple_t& p2) + -> range_t { + prtlidx_t p1min = p1[0]; + prtlidx_t p1max = p2[0]; + prtlidx_t p2min = p1[1]; + prtlidx_t p2max = p2[1]; + return Kokkos::MDRangePolicy, Kokkos::DefaultExecutionSpace>( + { p1min, p2min }, + { p1max, p2max }); } template <> auto CreateRangePolicy(const tuple_t& i1, const tuple_t& i2) -> range_t { - index_t i1min = i1[0]; - index_t i1max = i2[0]; + cellidx_t i1min = i1[0]; + cellidx_t i1max = i2[0]; return Kokkos::RangePolicy(i1min, i1max); } @@ -21,10 +39,10 @@ template <> auto CreateRangePolicy(const tuple_t& i1, const tuple_t& i2) -> range_t { - index_t i1min = i1[0]; - index_t i1max = i2[0]; - index_t i2min = i1[1]; - index_t i2max = i2[1]; + cellidx_t i1min = i1[0]; + cellidx_t i1max = i2[0]; + cellidx_t i2min = i1[1]; + cellidx_t i2max = i2[1]; return Kokkos::MDRangePolicy, Kokkos::DefaultExecutionSpace>( { i1min, i2min }, { i1max, i2max }); @@ -34,12 +52,12 @@ template <> auto CreateRangePolicy(const tuple_t& i1, const tuple_t& i2) -> range_t { - index_t i1min = i1[0]; - index_t i1max = i2[0]; - index_t i2min = i1[1]; - index_t i2max = i2[1]; - index_t i3min = i1[2]; - index_t i3max = i2[2]; + cellidx_t i1min = i1[0]; + cellidx_t i1max = i2[0]; + cellidx_t i2min = i1[1]; + cellidx_t i2max = i2[1]; + cellidx_t i3min = i1[2]; + cellidx_t i3max = i2[2]; return Kokkos::MDRangePolicy, Kokkos::DefaultExecutionSpace>( { i1min, i2min, i3min }, { i1max, i2max, i3max }); @@ -49,8 +67,8 @@ template <> auto CreateRangePolicyOnHost(const tuple_t& i1, const tuple_t& i2) -> range_h_t { - index_t i1min = i1[0]; - index_t i1max = i2[0]; + cellidx_t i1min = i1[0]; + cellidx_t i1max = i2[0]; return Kokkos::RangePolicy(i1min, i1max); } @@ -58,10 +76,10 @@ template <> auto CreateRangePolicyOnHost(const tuple_t& i1, const tuple_t& i2) -> range_h_t { - index_t i1min = i1[0]; - index_t i1max = i2[0]; - index_t i2min = i1[1]; - index_t i2max = i2[1]; + cellidx_t i1min = i1[0]; + cellidx_t i1max = i2[0]; + cellidx_t i2min = i1[1]; + cellidx_t i2max = i2[1]; return Kokkos::MDRangePolicy, Kokkos::DefaultHostExecutionSpace>( { i1min, i2min }, { i1max, i2max }); @@ -71,12 +89,12 @@ template <> auto CreateRangePolicyOnHost(const tuple_t& i1, const tuple_t& i2) -> range_h_t { - index_t i1min = i1[0]; - index_t i1max = i2[0]; - index_t i2min = i1[1]; - index_t i2max = i2[1]; - index_t i3min = i1[2]; - index_t i3max = i2[2]; + cellidx_t i1min = i1[0]; + cellidx_t i1max = i2[0]; + cellidx_t i2min = i1[1]; + cellidx_t i2max = i2[1]; + cellidx_t i3min = i1[2]; + cellidx_t i3max = i2[2]; return Kokkos::MDRangePolicy, Kokkos::DefaultHostExecutionSpace>( { i1min, i2min, i3min }, { i1max, i2max, i3max }); diff --git a/src/global/arch/kokkos_aliases.h b/src/global/arch/kokkos_aliases.h index 7569e2234..314e78c0e 100644 --- a/src/global/arch/kokkos_aliases.h +++ b/src/global/arch/kokkos_aliases.h @@ -227,10 +227,14 @@ using range_h_t = typename kokkos_aliases_hidden::range_h_impl::type; /** * @brief Function template for generating 1D Kokkos range policy for particles. - * @param p1 `npart_t`: min. - * @param p2 `npart_t`: max. + * @tparam D Dimension + * @param p1 array of size D `npart_t`: min. + * @param p2 array of size D `npart_t`: max. + * @returns Kokkos::RangePolicy or Kokkos::MDRangePolicy in the accelerator execution space. */ -auto CreateParticleRangePolicy(npart_t, npart_t) -> range_t; +template +auto CreateParticleRangePolicy(const tuple_t&, + const tuple_t&) -> range_t; /** * @brief Function template for generating ND Kokkos range policy. diff --git a/src/global/global.h b/src/global/global.h index faab7ee1d..08fbbf8b0 100644 --- a/src/global/global.h +++ b/src/global/global.h @@ -25,8 +25,21 @@ * - type list_t * - type coord_t * - type vec_t - * - type index_t - * - type range_tuple_t + * - type duration_t + * - type simtime_t + * - type timestep_t + * - type ncells_t + * - type npart_t + * - type timestamp_t + * - type cellidx_t + * - type prtlidx_t + * - type idx_t + * - type spidx_t + * - type dim_t + * - type path_t + * - type cell_range_t + * - type prtl_slice_t + * - type boundaries_t * - ntt::GlobalInitialize -> void * - ntt::GlobalFinalize -> void * - enum ntt::DiagFlags @@ -93,6 +106,7 @@ #define GLOBAL_GLOBAL_H #include +#include #include #include #include @@ -115,11 +129,10 @@ namespace ntt { #if !defined(SHAPE_ORDER) #define SHAPE_ORDER 0 - inline constexpr std::size_t N_GHOSTS = 2; + inline constexpr uint32_t N_GHOSTS = 2; #else // SHAPE_ORDER - inline constexpr std::size_t N_GHOSTS = static_cast( - (SHAPE_ORDER + 1) / 2) + - 1; + inline constexpr uint32_t N_GHOSTS = static_cast((SHAPE_ORDER + 1) / 2) + + 1; #endif // SHAPE_ORDER // Coordinate shift to account for ghost cells @@ -366,23 +379,25 @@ using vec_t = tuple_t; // time/duration using duration_t = double; using simtime_t = double; -using timestep_t = std::size_t; -using ncells_t = std::size_t; -using npart_t = unsigned long int; +using timestep_t = uint32_t; +using ncells_t = uint32_t; +using npart_t = uint64_t; // walltime using timestamp_t = std::chrono::time_point; // index/number -using index_t = const std::size_t; -using idx_t = unsigned short; -using spidx_t = unsigned short; -using dim_t = unsigned short; +using cellidx_t = const ncells_t; +using prtlidx_t = const npart_t; +using idx_t = uint8_t; +using spidx_t = uint8_t; +using dim_t = uint8_t; // utility using path_t = std::filesystem::path; -using range_tuple_t = std::pair; +using cell_range_t = std::pair; +using prtl_slice_t = std::pair; template using boundaries_t = std::vector>; diff --git a/src/global/traits/pgen.h b/src/global/traits/pgen.h index 39497c5ae..179c2dbc9 100644 --- a/src/global/traits/pgen.h +++ b/src/global/traits/pgen.h @@ -114,7 +114,7 @@ namespace traits::pgen { concept HasCustomFieldOutput = requires(PG& pgen, const std::string& name, ndfield_t& buff, - index_t idx, + cellidx_t idx, timestep_t step, simtime_t time, const DOM& dom) { diff --git a/src/global/traits/policies.h b/src/global/traits/policies.h index fae45b685..7f6d98985 100644 --- a/src/global/traits/policies.h +++ b/src/global/traits/policies.h @@ -127,7 +127,7 @@ namespace traits::custom_prtl_update { template concept CustomParticleUpdatePolicyClass = requires(const CPU& cpu, - index_t p, + prtlidx_t p, const kernel::sr::PusherContext& pusher_ctx, const kernel::sr::PusherBoundaries& pusher_boundaries, const ntt::ParticleArrays& particles, diff --git a/src/global/utils/error.h b/src/global/utils/error.h index df23bce62..611566a1a 100644 --- a/src/global/utils/error.h +++ b/src/global/utils/error.h @@ -56,6 +56,7 @@ namespace raise { (msg + " " + file + ":" + std::to_string(line) + " @ " + func).c_str()); } + [[noreturn]] inline void Fatal(const std::string& msg, const std::string& file, const std::string& func, diff --git a/src/global/utils/sorting.h b/src/global/utils/sorting.h index e1db97bde..0521145a3 100644 --- a/src/global/utils/sorting.h +++ b/src/global/utils/sorting.h @@ -116,7 +116,7 @@ namespace sort { } } - Inline auto operator()(index_t p) const { + Inline auto operator()(prtldx_t p) const { if (tag(p) != ntt::ParticleTag::alive) { tile_indices(p) = total_tiles + 1u; } else { diff --git a/src/kernels/ampere_gr.hpp b/src/kernels/ampere_gr.hpp index 2d44aa09e..65e85373a 100644 --- a/src/kernels/ampere_gr.hpp +++ b/src/kernels/ampere_gr.hpp @@ -62,7 +62,7 @@ namespace kernel::gr { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { constexpr ncells_t i2min { N_GHOSTS }; const real_t i1_ { COORD(i1) }; @@ -140,7 +140,7 @@ namespace kernel::gr { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { constexpr ncells_t i2min { N_GHOSTS }; const real_t i1_ { COORD(i1) }; diff --git a/src/kernels/ampere_mink.hpp b/src/kernels/ampere_mink.hpp index cee04e677..7c73ea590 100644 --- a/src/kernels/ampere_mink.hpp +++ b/src/kernels/ampere_mink.hpp @@ -45,7 +45,7 @@ namespace kernel::mink { , coeff1 { coeff1 } , coeff2 { coeff2 } {} - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { EB(i1, em::ex2) += coeff1 * (EB(i1 - 1, em::bx3) - EB(i1, em::bx3)); EB(i1, em::ex3) += coeff1 * (EB(i1, em::bx2) - EB(i1 - 1, em::bx2)); @@ -54,7 +54,7 @@ namespace kernel::mink { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { EB(i1, i2, em::ex1) += coeff1 * (EB(i1, i2, em::bx3) - EB(i1, i2 - 1, em::bx3)); @@ -68,7 +68,7 @@ namespace kernel::mink { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { EB(i1, i2, i3, em::ex1) += coeff1 * (EB(i1, i2, i3 - 1, em::bx2) - EB(i1, i2, i3, em::bx2) + @@ -131,7 +131,7 @@ namespace kernel::mink { real_t inv_n0) : CurrentsAmpere_kernel { E, J, coeff, inv_n0, NoCurrent_t {}, {}, ZERO } {} - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { if constexpr (ExtCurrent) { const auto i1_ = COORD(i1); @@ -153,7 +153,7 @@ namespace kernel::mink { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { if constexpr (ExtCurrent) { const auto i1_ = COORD(i1); @@ -180,7 +180,7 @@ namespace kernel::mink { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { if constexpr (ExtCurrent) { const auto i1_ = COORD(i1); diff --git a/src/kernels/ampere_sr.hpp b/src/kernels/ampere_sr.hpp index 22c6f0f8b..eb827ead6 100644 --- a/src/kernels/ampere_sr.hpp +++ b/src/kernels/ampere_sr.hpp @@ -55,7 +55,7 @@ namespace kernel::sr { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { constexpr ncells_t i2min { N_GHOSTS }; const real_t i1_ { COORD(i1) }; @@ -108,7 +108,7 @@ namespace kernel::sr { } } - Inline void operator()(index_t, index_t, index_t) const { + Inline void operator()(cellidx_t, cellidx_t, cellidx_t) const { if constexpr (D == Dim::_3D) { raise::KernelNotImplementedError(HERE); } else { @@ -160,7 +160,7 @@ namespace kernel::sr { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { const real_t i1_ { COORD(i1) }; const real_t i2_ { COORD(i2) }; @@ -208,7 +208,7 @@ namespace kernel::sr { } } - Inline void operator()(index_t, index_t, index_t) const { + Inline void operator()(cellidx_t, cellidx_t, cellidx_t) const { if constexpr (D == Dim::_3D) { raise::KernelNotImplementedError(HERE); } else { diff --git a/src/kernels/aux_fields_gr.hpp b/src/kernels/aux_fields_gr.hpp index 73f672ab8..5939d2f5a 100644 --- a/src/kernels/aux_fields_gr.hpp +++ b/src/kernels/aux_fields_gr.hpp @@ -46,7 +46,7 @@ namespace kernel::gr { , Ef { Ef } , metric { metric } {} - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { const real_t i1_ { COORD(i1) }; const real_t i2_ { COORD(i2) }; @@ -118,7 +118,7 @@ namespace kernel::gr { } } - Inline void operator()(index_t, index_t, index_t) const { + Inline void operator()(cellidx_t, cellidx_t, cellidx_t) const { if constexpr (D == Dim::_3D) { raise::KernelNotImplementedError(HERE); } else { @@ -152,7 +152,7 @@ namespace kernel::gr { , Hf { Hf } , metric { metric } {} - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { const real_t i1_ { COORD(i1) }; const real_t i2_ { COORD(i2) }; @@ -225,7 +225,7 @@ namespace kernel::gr { } } - Inline void operator()(index_t, index_t, index_t) const { + Inline void operator()(cellidx_t, cellidx_t, cellidx_t) const { if constexpr (D == Dim::_3D) { raise::KernelNotImplementedError(HERE); } else { @@ -250,7 +250,7 @@ namespace kernel::gr { : BDf { BDf } , BDf0 { BDf0 } {} - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { BDf0(i1, i2, em::bx1) = HALF * (BDf0(i1, i2, em::bx1) + BDf(i1, i2, em::bx1)); @@ -286,7 +286,7 @@ namespace kernel::gr { : Jf { Jf } , Jf0 { Jf0 } {} - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { Jf(i1, i2, cur::jx1) = HALF * (Jf0(i1, i2, cur::jx1) + Jf(i1, i2, cur::jx1)); diff --git a/src/kernels/comm.hpp b/src/kernels/comm.hpp index 332620675..6e8553961 100644 --- a/src/kernels/comm.hpp +++ b/src/kernels/comm.hpp @@ -27,8 +27,8 @@ namespace kernel::comm { const array_t shifts_in_x1, shifts_in_x2, shifts_in_x3; array_t outgoing_indices; - const npart_t npart, npart_alive, npart_dead; - const std::size_t ntags; + const npart_t npart, npart_alive, npart_dead; + const uint8_t ntags; array_t i1, i1_prev, i2, i2_prev, i3, i3_prev; const array_t tag; @@ -45,7 +45,7 @@ namespace kernel::comm { npart_t npart, npart_t npart_alive, npart_t npart_dead, - std::size_t ntags, + uint8_t ntags, array_t& i1, array_t& i1_prev, array_t& i2, @@ -72,7 +72,7 @@ namespace kernel::comm { , tag_offsets { tag_offsets } , current_offset { "current_offset", ntags } {} - Inline void operator()(index_t p) const { + Inline void operator()(prtlidx_t p) const { if (tag(p) != ParticleTag::alive) { // dead or to-be-sent auto idx_for_tag = Kokkos::atomic_fetch_add(¤t_offset(tag(p)), 1); @@ -190,7 +190,7 @@ namespace kernel::comm { , tag { tag } , outgoing_indices { outgoing_indices } {} - Inline void operator()(index_t p) const { + Inline void operator()(prtlidx_t p) const { const auto idx = outgoing_indices(idx_offset + p); if constexpr (D == Dim::_1D or D == Dim::_2D or D == Dim::_3D) { send_buff_int(NINTS * p + 0) = i1(idx); @@ -294,7 +294,7 @@ namespace kernel::comm { , NPLDS_R { NPLDS_R } , NPLDS_I { NPLDS_I } , npart { npart } - , npart_holes { outgoing_indices.extent(0) } + , npart_holes { static_cast(outgoing_indices.extent(0)) } , i1 { i1 } , i1_prev { i1_prev } , i2 { i2 } @@ -317,7 +317,7 @@ namespace kernel::comm { , tag { tag } , outgoing_indices { outgoing_indices } {} - Inline void operator()(index_t p) const { + Inline void operator()(prtlidx_t p) const { npart_t idx; if (p >= npart_holes) { idx = npart + p - npart_holes; diff --git a/src/kernels/currents_deposit.hpp b/src/kernels/currents_deposit.hpp index 879ae74a4..268187af2 100644 --- a/src/kernels/currents_deposit.hpp +++ b/src/kernels/currents_deposit.hpp @@ -105,7 +105,7 @@ namespace kernel { * @brief Iteration of the loop over particles. * @param p index. */ - Inline auto operator()(index_t p) const -> void { + Inline auto operator()(prtlidx_t p) const -> void { if (tag(p) == ParticleTag::dead) { return; } diff --git a/src/kernels/digital_filter.hpp b/src/kernels/digital_filter.hpp index 0bcada0fa..a4f1f9cba 100644 --- a/src/kernels/digital_filter.hpp +++ b/src/kernels/digital_filter.hpp @@ -96,7 +96,7 @@ namespace kernel { , i2_max { (short)D > 1 ? (size_[1] + N_GHOSTS) : 0 } , i3_max { (short)D > 2 ? (size_[2] + N_GHOSTS) : 0 } {} - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr ((D == Dim::_1D) && (C == Coord::Cartesian)) { if ((is_conductor_i1min and i1 == i1_min) or (is_conductor_i1max and i1 == i1_max - 1)) { @@ -126,7 +126,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { if constexpr (C == Coord::Cartesian) { if ((is_conductor_i1min and i1 == i1_min) or @@ -286,7 +286,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { if constexpr (C == Coord::Cartesian) { if ((is_conductor_i1min and i1 == i1_min) or diff --git a/src/kernels/divergences.hpp b/src/kernels/divergences.hpp index 7151ef024..6454665a8 100644 --- a/src/kernels/divergences.hpp +++ b/src/kernels/divergences.hpp @@ -42,7 +42,7 @@ namespace kernel { raise::ErrorIf(buff_idx >= N, "Invalid component index", HERE); } - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (M::Dim == Dim::_1D) { if constexpr (M::CoordType == Coord::Cartesian) { buff(i1, buff_idx) = fields(i1, em::ex1) - fields(i1 - 1, em::ex1); @@ -61,7 +61,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (M::Dim == Dim::_2D) { if constexpr (M::CoordType == Coord::Cartesian) { buff(i1, i2, buff_idx) = fields(i1, i2, em::ex1) - @@ -85,7 +85,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (M::Dim == Dim::_3D) { if constexpr (M::CoordType == Coord::Cartesian) { buff(i1, i2, i3, buff_idx) = fields(i1, i2, i3, em::ex1) - diff --git a/src/kernels/faraday_gr.hpp b/src/kernels/faraday_gr.hpp index 02420f896..555e087d6 100644 --- a/src/kernels/faraday_gr.hpp +++ b/src/kernels/faraday_gr.hpp @@ -46,7 +46,7 @@ namespace kernel::gr { const ndfield_t& E, const M& metric, real_t coeff, - std::size_t ni2, + ncells_t ni2, const boundaries_t& boundaries) : Bin { Bin } , Bout { Bout } @@ -60,14 +60,14 @@ namespace kernel::gr { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { - constexpr std::size_t i2min { N_GHOSTS }; - const real_t i1_ { COORD(i1) }; - const real_t i2_ { COORD(i2) }; - const real_t inv_sqrt_detH_0pH { ONE / + constexpr ncells_t i2min { N_GHOSTS }; + const real_t i1_ { COORD(i1) }; + const real_t i2_ { COORD(i2) }; + const real_t inv_sqrt_detH_0pH { ONE / metric.sqrt_det_h({ i1_, i2_ + HALF }) }; - const real_t inv_sqrt_detH_pHpH { ONE / metric.sqrt_det_h( + const real_t inv_sqrt_detH_pHpH { ONE / metric.sqrt_det_h( { i1_ + HALF, i2_ + HALF }) }; Bout(i1, i2, em::bx1) = Bin(i1, i2, em::bx1) + @@ -92,7 +92,7 @@ namespace kernel::gr { } } - Inline void operator()(index_t, index_t, index_t) const { + Inline void operator()(cellidx_t, cellidx_t, cellidx_t) const { if constexpr (D == Dim::_3D) { raise::KernelNotImplementedError(HERE); } else { diff --git a/src/kernels/faraday_mink.hpp b/src/kernels/faraday_mink.hpp index cf6844a9d..db84816bd 100644 --- a/src/kernels/faraday_mink.hpp +++ b/src/kernels/faraday_mink.hpp @@ -68,7 +68,7 @@ namespace kernel::mink { , betayz { betayz } , betazy { betazy } {} - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { const auto alphax = ONE - THREE * deltax; // clang-format off @@ -84,7 +84,7 @@ namespace kernel::mink { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { const auto alphax = ONE - TWO * betaxy - THREE * deltax; const auto alphay = ONE - TWO * betayx - THREE * deltay; @@ -114,7 +114,7 @@ namespace kernel::mink { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { const auto alphax = ONE - TWO * betaxy - TWO * betaxz - THREE * deltax; const auto alphay = ONE - TWO * betayx - TWO * betayz - THREE * deltay; diff --git a/src/kernels/faraday_sr.hpp b/src/kernels/faraday_sr.hpp index 1f061dfe8..0157d08da 100644 --- a/src/kernels/faraday_sr.hpp +++ b/src/kernels/faraday_sr.hpp @@ -50,7 +50,7 @@ namespace kernel::sr { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { constexpr ncells_t i2min { N_GHOSTS }; const real_t i1_ { COORD(i1) }; @@ -88,7 +88,7 @@ namespace kernel::sr { } } - Inline void operator()(index_t, index_t, index_t) const { + Inline void operator()(cellidx_t, cellidx_t, cellidx_t) const { if constexpr (D == Dim::_3D) { raise::KernelNotImplementedError(HERE); } else { diff --git a/src/kernels/fields_bcs.hpp b/src/kernels/fields_bcs.hpp index 3dcf3191b..73c023484 100644 --- a/src/kernels/fields_bcs.hpp +++ b/src/kernels/fields_bcs.hpp @@ -90,7 +90,7 @@ namespace kernel::bc { return math::tanh(dx * FOUR / dx_abs); } - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (M::Dim == Dim::_1D) { const auto i1_ = COORD(i1); @@ -173,7 +173,7 @@ namespace kernel::bc { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (M::Dim == Dim::_2D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); @@ -343,7 +343,7 @@ namespace kernel::bc { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (M::Dim == Dim::_3D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); @@ -525,16 +525,16 @@ namespace kernel::bc { static_assert(static_cast(o) < static_cast(D), "Invalid component index"); - ndfield_t Fld; - const std::size_t i_edge; - const BCTags tags; + ndfield_t Fld; + const ncells_t i_edge; + const BCTags tags; - ConductorBoundaries_kernel(ndfield_t& Fld, std::size_t i_edge, BCTags tags) + ConductorBoundaries_kernel(ndfield_t& Fld, ncells_t i_edge, BCTags tags) : Fld { Fld } , i_edge { i_edge } , tags { tags } {} - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { if (tags & BC::E) { if (i1 == 0) { @@ -575,7 +575,7 @@ namespace kernel::bc { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { if constexpr (o == in::x1) { if (tags & BC::E) { @@ -651,7 +651,7 @@ namespace kernel::bc { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { if constexpr (o == in::x1) { if (tags & BC::E) { @@ -825,7 +825,7 @@ namespace kernel::bc { struct AxisBoundaries_kernel { ndfield_t Fld; const ncells_t i_edge; - const bool setE, setB; + const bool setE { false }, setB { false }; AxisBoundaries_kernel(ndfield_t Fld, ncells_t i_edge, BCTags tags) : Fld { Fld } @@ -833,7 +833,7 @@ namespace kernel::bc { , setE { tags & BC::Ex1 or tags & BC::Ex2 or tags & BC::Ex3 } , setB { tags & BC::Bx1 or tags & BC::Bx2 or tags & BC::Bx3 } {} - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_2D) { // ! TODO: not all components are necessary if constexpr (not P) { @@ -896,7 +896,7 @@ namespace kernel::bc { , i_edge { i_edge + N_GHOSTS } , tags { tags } {} - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { const auto i1_ = COORD(i1); coord_t x_Ph_0 { ZERO }; @@ -971,7 +971,7 @@ namespace kernel::bc { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); @@ -1065,7 +1065,7 @@ namespace kernel::bc { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); @@ -1186,15 +1186,15 @@ namespace kernel::bc { template struct HorizonBoundaries_kernel { - ndfield_t Fld; - const std::size_t i1_min; - const bool setE, setB; - const std::size_t nfilter; + ndfield_t Fld; + const ncells_t i1_min; + const bool setE { false }, setB { false }; + const ncells_t nfilter; HorizonBoundaries_kernel(ndfield_t Fld, - std::size_t i1_min, + ncells_t i1_min, BCTags tags, - std::size_t nfilter) + ncells_t nfilter) : Fld { Fld } , i1_min { i1_min } , setE { (tags & BC::Ex1 or tags & BC::Ex2 or tags & BC::Ex3) or @@ -1203,7 +1203,7 @@ namespace kernel::bc { (tags & BC::Hx1 or tags & BC::Hx2 or tags & BC::Hx3) } , nfilter { nfilter } {} - Inline void operator()(index_t i2) const { + Inline void operator()(cellidx_t i2) const { if constexpr (D == Dim::_2D) { if (setE) { for (unsigned short i = 0; i <= 2 + nfilter; ++i) { @@ -1258,7 +1258,7 @@ namespace kernel::bc { , xg_edge { xg_edge } , dx_abs { dx_abs } {} - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (M::Dim == Dim::_2D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); diff --git a/src/kernels/fields_to_phys.hpp b/src/kernels/fields_to_phys.hpp index 3f220214f..bc778ee02 100644 --- a/src/kernels/fields_to_phys.hpp +++ b/src/kernels/fields_to_phys.hpp @@ -69,7 +69,7 @@ namespace kernel { HERE); } - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { const real_t i1_ { COORD(i1) }; vec_t f_int { ZERO }, f_fin { ZERO }; @@ -118,7 +118,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { const real_t i1_ { COORD(i1) }; const real_t i2_ { COORD(i2) }; @@ -172,7 +172,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { const real_t i1_ { COORD(i1) }; const real_t i2_ { COORD(i2) }; diff --git a/src/kernels/injectors.hpp b/src/kernels/injectors.hpp index 71fe4cfe9..05d83a0d4 100644 --- a/src/kernels/injectors.hpp +++ b/src/kernels/injectors.hpp @@ -190,7 +190,7 @@ namespace kernel { } } - Inline void operator()(index_t p) const { + Inline void operator()(prtlidx_t p) const { coord_t x_Cd { ZERO }; tuple_t xi_Cd { 0 }; tuple_t dxi_Cd { static_cast(0) }; @@ -395,7 +395,7 @@ namespace kernel { return idx_h(); } - Inline void operator()(index_t p) const { + Inline void operator()(prtlidx_t p) const { bool should_inject { false }; tuple_t xi_Cd { 0 }; tuple_t dxi_Cd { static_cast(0) }; @@ -624,7 +624,7 @@ namespace kernel { return ppc; } - Inline void inject1(const index_t index, + Inline void inject1(const prtlidx_t index, const tuple_t& xi_Cd, const tuple_t& dxi_Cd, const vec_t& v_Cd, @@ -649,7 +649,7 @@ namespace kernel { // clang-format on } - Inline void inject2(const index_t index, + Inline void inject2(const prtlidx_t index, const tuple_t& xi_Cd, const tuple_t& dxi_Cd, const vec_t& v_Cd, @@ -674,7 +674,7 @@ namespace kernel { // clang-format on } - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (M::Dim == Dim::_1D) { const auto i1_ = COORD(i1); const coord_t x_Cd { i1_ + HALF }; @@ -717,7 +717,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (M::Dim == Dim::_2D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); @@ -786,7 +786,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (M::Dim == Dim::_3D) { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); diff --git a/src/kernels/particle_moments.hpp b/src/kernels/particle_moments.hpp index 51d39d40c..f05edf801 100644 --- a/src/kernels/particle_moments.hpp +++ b/src/kernels/particle_moments.hpp @@ -129,7 +129,7 @@ namespace kernel { } } - Inline auto computeStressEnergyComponent(index_t p) const -> real_t { + Inline auto computeStressEnergyComponent(prtlidx_t p) const -> real_t { real_t u0 { ZERO }; vec_t u_Phys { ZERO }; if constexpr (S == SimEngine::SRPIC) { @@ -189,7 +189,7 @@ namespace kernel { return T_component; } - Inline auto computeBulk3VelocityTimesMass(index_t p) const -> real_t { + Inline auto computeBulk3VelocityTimesMass(prtlidx_t p) const -> real_t { real_t u0 { ZERO }; // for bulk 3vel (tetrad basis) vec_t u_Phys { ZERO }; @@ -219,7 +219,7 @@ namespace kernel { return (mass == ZERO ? ONE : mass) * u_Phys[c1 - 1] / u0; } - Inline void operator()(index_t p) const { + Inline void operator()(prtlidx_t p) const { if (tag(p) == ParticleTag::dead) { return; } @@ -347,7 +347,7 @@ namespace kernel { HERE); } - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { if constexpr (D == Dim::_1D) { if (not cmp::AlmostZero(Rho(i1, c_rho))) { Vector(i1, c_v1) /= Rho(i1, c_rho); @@ -361,7 +361,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (D == Dim::_2D) { if (not cmp::AlmostZero(Rho(i1, i2, c_rho))) { Vector(i1, i2, c_v1) /= Rho(i1, i2, c_rho); @@ -375,7 +375,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (D == Dim::_3D) { if (not cmp::AlmostZero(Rho(i1, i2, i3, c_rho))) { Vector(i1, i2, i3, c_v1) /= Rho(i1, i2, i3, c_rho); diff --git a/src/kernels/prtls_to_phys.hpp b/src/kernels/prtls_to_phys.hpp index 7da808413..b2f570a5d 100644 --- a/src/kernels/prtls_to_phys.hpp +++ b/src/kernels/prtls_to_phys.hpp @@ -117,7 +117,7 @@ namespace kernel { raise::ErrorIf(buff_ux3.extent(0) == 0, "Invalid buffer size", HERE); } - Inline void operator()(index_t p) const { + Inline void operator()(prtlidx_t p) const { if constexpr (not T) { // no tracking enabled bufferX(p * stride, p); bufferU(p * stride, p); @@ -131,7 +131,7 @@ namespace kernel { } } - Inline void bufferX(index_t p_from, index_t p_to) const { + Inline void bufferX(prtlidx_t p_from, prtlidx_t p_to) const { if constexpr ((D == Dim::_1D) || (D == Dim::_2D) || (D == Dim::_3D)) { buff_x1(p_to) = metric.template convert<1, Crd::Cd, Crd::Ph>( static_cast(i1(p_from)) + static_cast(dx1(p_from))); @@ -148,7 +148,7 @@ namespace kernel { } } - Inline void bufferU(index_t p_from, index_t p_to) const { + Inline void bufferU(prtlidx_t p_from, prtlidx_t p_to) const { vec_t u_Phys { ZERO }; if constexpr (D == Dim::_1D) { if constexpr (M::CoordType == Coord::Cartesian) { @@ -206,7 +206,7 @@ namespace kernel { buff_ux3(p_to) = u_Phys[2]; } - Inline void bufferPlds(index_t p_from, index_t p_to) const { + Inline void bufferPlds(prtlidx_t p_from, prtlidx_t p_to) const { for (auto pr { 0u }; pr < buff_pldr.extent(1); ++pr) { buff_pldr(p_to, pr) = pld_r(p_from, pr); } diff --git a/src/kernels/pushers/gr.hpp b/src/kernels/pushers/gr.hpp index 1dddaa40b..ff3274bac 100644 --- a/src/kernels/pushers/gr.hpp +++ b/src/kernels/pushers/gr.hpp @@ -105,12 +105,12 @@ namespace kernel::gr { /** * @brief Main pusher subroutine for photon particles. */ - Inline void operator()(Massless_t, index_t) const; + Inline void operator()(Massless_t, prtlidx_t) const; /** * @brief Main pusher subroutine for massive particles. */ - Inline void operator()(Massive_t, index_t) const; + Inline void operator()(Massive_t, prtlidx_t) const; /** * @brief Iterative geodesic pusher substep for momentum only. @@ -225,7 +225,7 @@ namespace kernel::gr { * @param b interpolated b-field vector of size 3 [return]. */ template - Inline void interpolateFields(index_t p, + Inline void interpolateFields(prtlidx_t p, vec_t& e, vec_t& b) const; @@ -250,7 +250,7 @@ namespace kernel::gr { } // Extra - Inline void boundaryConditions(index_t) const; + Inline void boundaryConditions(prtlidx_t) const; }; /* -------------------------------------------------------------------------- */ @@ -464,7 +464,7 @@ namespace kernel::gr { template template - Inline void Pusher_kernel::interpolateFields(index_t p, + Inline void Pusher_kernel::interpolateFields(prtlidx_t p, vec_t& e0, vec_t& b0) const { @@ -648,7 +648,7 @@ namespace kernel::gr { /* ------------------------------ Photon pusher ----------------------------- */ template - Inline void Pusher_kernel::operator()(Massless_t, index_t p) const { + Inline void Pusher_kernel::operator()(Massless_t, prtlidx_t p) const { if constexpr (D == Dim::_1D) { raise::KernelError(HERE, "Photon pusher not implemented for 1D"); } else if constexpr (D == Dim::_2D) { @@ -708,7 +708,7 @@ namespace kernel::gr { /* ------------------------- Massive particle pusher ------------------------ */ template - Inline void Pusher_kernel::operator()(Massive_t, index_t p) const { + Inline void Pusher_kernel::operator()(Massive_t, prtlidx_t p) const { if constexpr (D == Dim::_1D) { raise::KernelError(HERE, "Massive pusher not implemented for 1D"); } else if constexpr (D == Dim::_2D) { @@ -800,7 +800,7 @@ namespace kernel::gr { // Boundary conditions template - Inline void Pusher_kernel::boundaryConditions(index_t p) const { + Inline void Pusher_kernel::boundaryConditions(prtlidx_t p) const { if constexpr (D == Dim::_1D || D == Dim::_2D || D == Dim::_3D) { if ((particles.i1(p) < 0 && bc.is_absorb_i1min) or (particles.i1(p) >= ctx.ni1 && bc.is_absorb_i1max)) { diff --git a/src/kernels/pushers/sr.hpp b/src/kernels/pushers/sr.hpp index 08188fb3c..78b5c4916 100644 --- a/src/kernels/pushers/sr.hpp +++ b/src/kernels/pushers/sr.hpp @@ -114,7 +114,7 @@ namespace kernel::sr { HERE); } - Inline void operator()(index_t p) const { + Inline void operator()(prtlidx_t p) const { if (particles.tag(p) != ParticleTag::alive) { if (particles.tag(p) != ParticleTag::dead) { raise::KernelError(HERE, "Invalid particle tag in pusher"); @@ -334,7 +334,7 @@ namespace kernel::sr { // ....................... // velocity pushers // ....................... - Inline void velocityEMPush_Boris(index_t p, + Inline void velocityEMPush_Boris(prtlidx_t p, vec_t& e0, vec_t& b0) const { real_t COEFF { normalized_dt_half }; @@ -367,7 +367,7 @@ namespace kernel::sr { particles.ux3(p) = u0[2]; } - Inline void velocityEMPush_Vay(index_t p, + Inline void velocityEMPush_Vay(prtlidx_t p, vec_t& e0, vec_t& b0) const { auto COEFF { normalized_dt_half }; @@ -436,7 +436,7 @@ namespace kernel::sr { u1[0] * b0[1] * COEFF - u1[1] * b0[0] * COEFF); } - Inline void velocityEMPush_GCA(index_t p, + Inline void velocityEMPush_GCA(prtlidx_t p, vec_t& e0, vec_t& b0) const { const auto eb_sqr { NORM_SQR(e0[0], e0[1], e0[2]) + @@ -477,7 +477,7 @@ namespace kernel::sr { particles.ux3(p) = upar * b0[2] + vE_Cart[2] * Gamma; } - Inline void velocityEMPush_GCA_ExtForce(index_t p, + Inline void velocityEMPush_GCA_ExtForce(prtlidx_t p, vec_t& f0, vec_t& e0, vec_t& b0) const { @@ -523,7 +523,7 @@ namespace kernel::sr { // ....................... // position pusher & bcs // ....................... - Inline void positionPush(bool massive, index_t p, coord_t& xp) const { + Inline void positionPush(bool massive, prtlidx_t p, coord_t& xp) const { // get cartesian velocity if constexpr (M::CoordType == Coord::Cartesian) { // i+di push for Cartesian basis @@ -656,7 +656,7 @@ namespace kernel::sr { boundaryConditions(p, xp); } - Inline void boundaryConditions(index_t p, + Inline void boundaryConditions(prtlidx_t p, coord_t& xp_VelAligned) const { if constexpr (D == Dim::_1D || D == Dim::_2D || D == Dim::_3D) { auto invert_vel = false; @@ -816,7 +816,7 @@ namespace kernel::sr { // ....................... // helper functions // ....................... - Inline void getParticlePosition(index_t p, coord_t& xp) const { + Inline void getParticlePosition(prtlidx_t p, coord_t& xp) const { if constexpr (D == Dim::_1D || D == Dim::_2D || D == Dim::_3D) { xp[0] = i_di_to_Xi(particles.i1(p), particles.dx1(p)); } @@ -832,7 +832,7 @@ namespace kernel::sr { } } - Inline void getParticlePrevPosition(index_t p, coord_t& xp) const { + Inline void getParticlePrevPosition(prtlidx_t p, coord_t& xp) const { if constexpr (D == Dim::_1D || D == Dim::_2D || D == Dim::_3D) { xp[0] = i_di_to_Xi(particles.i1_prev(p), particles.dx1_prev(p)); } @@ -849,7 +849,7 @@ namespace kernel::sr { } template - Inline void getInterpolatedEMFields(index_t p, + Inline void getInterpolatedEMFields(prtlidx_t p, vec_t& e0, vec_t& b0) const { @@ -1369,7 +1369,7 @@ namespace kernel::sr { } } - Inline void synchrotronDrag(index_t p, + Inline void synchrotronDrag(prtlidx_t p, vec_t& u_prime, const vec_t& e0, const vec_t& b0) const { @@ -1484,7 +1484,7 @@ namespace kernel::sr { external_force_Cart); } - Inline void inverseComptonDrag(index_t p, vec_t& u_prime) const { + Inline void inverseComptonDrag(prtlidx_t p, vec_t& u_prime) const { real_t gamma_prime_sqr = ONE / math::sqrt(ONE + NORM_SQR(u_prime[0], u_prime[1], u_prime[2])); @@ -1498,7 +1498,7 @@ namespace kernel::sr { particles.ux3(p) -= ctx.compton_drag.coeff * gamma_prime_sqr * u_prime[2]; } - Inline void processEmission(index_t p, + Inline void processEmission(prtlidx_t p, vec_t& u_prime, const coord_t& xp_Cd, const coord_t& xp_Ph, diff --git a/src/kernels/reduced_stats.hpp b/src/kernels/reduced_stats.hpp index a5aab8feb..d6a00a59e 100644 --- a/src/kernels/reduced_stats.hpp +++ b/src/kernels/reduced_stats.hpp @@ -37,7 +37,7 @@ namespace kernel { , J { J } , metric { metric } {} - Inline void operator()(index_t i1, real_t& buff) const { + Inline void operator()(cellidx_t i1, real_t& buff) const { const auto i1_ = COORD(i1); if constexpr (F == StatsID::B2) { if constexpr (I == 1) { @@ -140,7 +140,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2, real_t& buff) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, real_t& buff) const { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); if constexpr (F == StatsID::B2) { @@ -254,7 +254,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2, index_t i3, real_t& buff) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3, real_t& buff) const { const auto i1_ = COORD(i1); const auto i2_ = COORD(i2); const auto i3_ = COORD(i3); @@ -460,7 +460,7 @@ namespace kernel { HERE); } - Inline void operator()(index_t p, real_t& buff) const { + Inline void operator()(prtlidx_t p, real_t& buff) const { if (tag(p) != ParticleTag::alive) { return; } diff --git a/src/kernels/utils.hpp b/src/kernels/utils.hpp index 628ed267f..e8861b3b2 100644 --- a/src/kernels/utils.hpp +++ b/src/kernels/utils.hpp @@ -30,7 +30,7 @@ namespace kernel { raise::ErrorIf(buff_idx >= N, "Invalid component index", HERE); } - Inline void operator()(index_t i1, real_t& lsum) const { + Inline void operator()(cellidx_t i1, real_t& lsum) const { if constexpr (D == Dim::_1D) { lsum += buff(i1, buff_idx); } else { @@ -40,7 +40,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2, real_t& lsum) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, real_t& lsum) const { if (D == Dim::_2D) { lsum += buff(i1, i2, buff_idx); } else { @@ -50,7 +50,7 @@ namespace kernel { } } - Inline void operator()(index_t i1, index_t i2, index_t i3, real_t& lsum) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3, real_t& lsum) const { if (D == Dim::_3D) { lsum += buff(i1, i2, i3, buff_idx); } else { diff --git a/src/metrics/kerr_schild.h b/src/metrics/kerr_schild.h index 57d1cc909..6189e965e 100644 --- a/src/metrics/kerr_schild.h +++ b/src/metrics/kerr_schild.h @@ -36,11 +36,11 @@ namespace metric { // Spin parameter, in [0,1[ // and horizon size in units of rg // all physical extents are in units of rg - const real_t a, rg_, rh_; + const real_t a, rg_ { ONE }, rh_; const real_t dr, dtheta, dphi; const real_t dr_inv, dtheta_inv, dphi_inv; - const bool small_angle; + const bool small_angle { false }; Inline auto Delta(real_t r) const -> real_t { return SQR(r) - TWO * r + SQR(a); @@ -79,7 +79,6 @@ namespace metric { const std::map& params) : MetricBase { res, ext } , a { params.at("a") } - , rg_ { ONE } , rh_ { ONE + math::sqrt(ONE - SQR(a)) } , dr { (x1_max - x1_min) / nx1 } , dtheta { (x2_max - x2_min) / nx2 } diff --git a/src/metrics/kerr_schild_0.h b/src/metrics/kerr_schild_0.h index bdab8b592..006e4f5c4 100644 --- a/src/metrics/kerr_schild_0.h +++ b/src/metrics/kerr_schild_0.h @@ -34,7 +34,7 @@ namespace metric { static_assert(D != Dim::_3D, "3D kerr_schild_0 not fully implemented"); private: - const real_t a, rg_, rh_; + const real_t a { ZERO }, rg_ { ONE }, rh_ { TWO }; const real_t dr, dtheta, dphi; const real_t dr_inv, dtheta_inv, dphi_inv; @@ -58,9 +58,6 @@ namespace metric { const boundaries_t& ext, const std::map& = {}) : MetricBase { res, ext } - , a { ZERO } - , rg_ { ONE } - , rh_ { TWO } , dr { (x1_max - x1_min) / nx1 } , dtheta { (x2_max - x2_min) / nx2 } , dphi { (x3_max - x3_min) / nx3 } diff --git a/src/metrics/qkerr_schild.h b/src/metrics/qkerr_schild.h index 994dd4202..ed5652a5d 100644 --- a/src/metrics/qkerr_schild.h +++ b/src/metrics/qkerr_schild.h @@ -33,7 +33,7 @@ namespace metric { // Spin parameter, in [0,1[ // and horizon size in units of rg // all physical extents are in units of rg - const real_t a, rg_, rh_; + const real_t a, rg_ { ONE }, rh_; const real_t r0, h0; const real_t chi_min, eta_min, phi_min; @@ -78,7 +78,6 @@ namespace metric { const std::map& params) : MetricBase { res, ext } , a { params.at("a") } - , rg_ { ONE } , rh_ { ONE + math::sqrt(ONE - SQR(a)) } , r0 { params.at("r0") } , h0 { params.at("h") } diff --git a/src/metrics/spherical.h b/src/metrics/spherical.h index 366c394a3..72ca69368 100644 --- a/src/metrics/spherical.h +++ b/src/metrics/spherical.h @@ -33,7 +33,7 @@ namespace metric { const real_t dr, dtheta, dphi; const real_t dr_inv, dtheta_inv, dphi_inv; - const bool small_angle; + const bool small_angle { false }; public: static constexpr const char* Label { "spherical" }; diff --git a/src/output/utils/readers.cpp b/src/output/utils/readers.cpp index 7883f7431..07e666caf 100644 --- a/src/output/utils/readers.cpp +++ b/src/output/utils/readers.cpp @@ -10,6 +10,7 @@ #include #include +#include namespace out { @@ -40,7 +41,7 @@ namespace out { auto var = io.InquireVariable(quantity); if (var) { var.SetSelection(adios2::Box({ local_offset }, { local_size })); - const auto slice = range_tuple_t(0, local_size); + const auto slice = std::pair(0, local_size); auto data_h = Kokkos::create_mirror_view(data); reader.Get(var, Kokkos::subview(data_h, slice).data(), adios2::Mode::Sync); Kokkos::deep_copy(Kokkos::subview(data, slice), @@ -62,16 +63,19 @@ namespace out { if (var) { var.SetSelection(adios2::Box({ local_offset * dim2_size }, { local_size * dim2_size })); - const auto slice = range_tuple_t(0, local_size); - auto data_h = Kokkos::create_mirror_view(data); - auto data_sub = Kokkos::subview(data_h, slice, range_tuple_t(0, dim2_size)); + const auto slice = std::pair(0, local_size); + auto data_h = Kokkos::create_mirror_view(data); + auto data_sub = Kokkos::subview(data_h, + slice, + std::pair(0, dim2_size)); if (!data_sub.span_is_contiguous()) { const Kokkos::View data_contig_h { "data_contig_h", local_size, dim2_size }; reader.Get(var, data_contig_h.data(), adios2::Mode::Sync); - Kokkos::deep_copy( - data_sub, - Kokkos::subview(data_contig_h, slice, range_tuple_t(0, dim2_size))); + Kokkos::deep_copy(data_sub, + Kokkos::subview(data_contig_h, + slice, + std::pair(0, dim2_size))); } else { reader.Get(var, data_sub.data(), adios2::Mode::Sync); } diff --git a/src/output/utils/writers.cpp b/src/output/utils/writers.cpp index 7c976f67d..a02f298e4 100644 --- a/src/output/utils/writers.cpp +++ b/src/output/utils/writers.cpp @@ -8,6 +8,7 @@ #include #include +#include namespace out { @@ -32,7 +33,7 @@ namespace out { std::size_t local_size, std::size_t global_size, std::size_t local_offset) { - const auto slice = range_tuple_t(0, local_size); + const auto slice = std::pair(0, local_size); auto var = io.InquireVariable(name); var.SetShape({ global_size }); var.SetSelection(adios2::Box({ local_offset }, { local_size })); @@ -52,7 +53,7 @@ namespace out { std::size_t local_size, std::size_t global_size, std::size_t local_offset) { - const auto slice = range_tuple_t(0, local_size); + const auto slice = std::pair(0, local_size); auto var = io.InquireVariable(name); var.SetShape({ global_size * dim2_size }); @@ -61,7 +62,9 @@ namespace out { auto data_h = Kokkos::create_mirror_view(data); Kokkos::deep_copy(data_h, data); - auto data_sub = Kokkos::subview(data_h, slice, range_tuple_t(0, dim2_size)); + auto data_sub = Kokkos::subview(data_h, + slice, + std::pair(0, dim2_size)); if (!data_sub.span_is_contiguous()) { const Kokkos::View data_contig_h { "data_contig_h", local_size, dim2_size }; diff --git a/src/output/writer.cpp b/src/output/writer.cpp index de411418c..815ebf622 100644 --- a/src/output/writer.cpp +++ b/src/output/writer.cpp @@ -67,9 +67,9 @@ namespace out { } void Writer::defineMeshLayout( - const std::vector& glob_shape, - const std::vector& loc_corner, - const std::vector& loc_shape, + const std::vector& glob_shape, + const std::vector& loc_corner, + const std::vector& loc_shape, const std::pair& domain_idx, const std::vector& dwn, bool incl_ghosts, @@ -97,7 +97,8 @@ namespace out { m_flds_l_shape_dwn.push_back(static_cast(math::ceil((n - f) / d))); } - m_io.DefineAttribute("NGhosts", incl_ghosts ? N_GHOSTS : 0); + m_io.DefineAttribute("NGhosts", + incl_ghosts ? N_GHOSTS : static_cast(0)); m_io.DefineAttribute("Dimension", m_flds_g_shape.size()); m_io.DefineAttribute("Coordinates", std::string(coords.to_string())); @@ -197,7 +198,7 @@ namespace out { if constexpr (D == Dim::_1D) { if (ghosts || dwn[0] == 1) { - auto slice_i1 = range_tuple_t(gh_zones, field.extent(0) - gh_zones); + auto slice_i1 = cell_range_t(gh_zones, field.extent(0) - gh_zones); auto slice = Kokkos::subview(field, slice_i1, comp); output_field = array_t { "output_field", slice.extent(0) }; Kokkos::deep_copy(output_field, slice); @@ -215,14 +216,14 @@ namespace out { Kokkos::parallel_for( "outputField", nx1_dwn, - Lambda(index_t i1) { + Lambda(cellidx_t i1) { output_field(i1) = field(first_cell1 + i1 * dwn1 + N_GHOSTS, comp); }); } } else if constexpr (D == Dim::_2D) { if (ghosts || (dwn[0] == 1 && dwn[1] == 1)) { - auto slice_i1 = range_tuple_t(gh_zones, field.extent(0) - gh_zones); - auto slice_i2 = range_tuple_t(gh_zones, field.extent(1) - gh_zones); + auto slice_i1 = cell_range_t(gh_zones, field.extent(0) - gh_zones); + auto slice_i2 = cell_range_t(gh_zones, field.extent(1) - gh_zones); auto slice = Kokkos::subview(field, slice_i1, slice_i2, comp); output_field = array_t { "output_field", slice.extent(0), @@ -246,7 +247,7 @@ namespace out { Kokkos::parallel_for( "outputField", CreateRangePolicy({ 0, 0 }, { nx1_dwn, nx2_dwn }), - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { output_field(i1, i2) = field(first_cell1 + i1 * dwn1 + N_GHOSTS, first_cell2 + i2 * dwn2 + N_GHOSTS, comp); @@ -254,9 +255,9 @@ namespace out { } } else if constexpr (D == Dim::_3D) { if (ghosts || (dwn[0] == 1 && dwn[1] == 1 && dwn[2] == 1)) { - auto slice_i1 = range_tuple_t(gh_zones, field.extent(0) - gh_zones); - auto slice_i2 = range_tuple_t(gh_zones, field.extent(1) - gh_zones); - auto slice_i3 = range_tuple_t(gh_zones, field.extent(2) - gh_zones); + auto slice_i1 = cell_range_t(gh_zones, field.extent(0) - gh_zones); + auto slice_i2 = cell_range_t(gh_zones, field.extent(1) - gh_zones); + auto slice_i3 = cell_range_t(gh_zones, field.extent(2) - gh_zones); auto slice = Kokkos::subview(field, slice_i1, slice_i2, slice_i3, comp); output_field = array_t { "output_field", slice.extent(0), @@ -288,7 +289,7 @@ namespace out { Kokkos::parallel_for( "outputField", CreateRangePolicy({ 0, 0, 0 }, { nx1_dwn, nx2_dwn, nx3_dwn }), - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { output_field(i1, i2, i3) = field(first_cell1 + i1 * dwn1 + N_GHOSTS, first_cell2 + i2 * dwn2 + N_GHOSTS, first_cell3 + i3 * dwn3 + N_GHOSTS, @@ -304,7 +305,7 @@ namespace out { template void Writer::writeField(const std::vector& names, const ndfield_t& fld, - const std::vector& addresses) { + const std::vector& addresses) { raise::ErrorIf(addresses.size() > N, "addresses vector size must be less than N", HERE); diff --git a/src/output/writer.h b/src/output/writer.h index 86c5969c6..5e4ce1a52 100644 --- a/src/output/writer.h +++ b/src/output/writer.h @@ -90,9 +90,9 @@ namespace out { void writeAttrs(const prm::Parameters&); - void defineMeshLayout(const std::vector&, - const std::vector&, - const std::vector&, + void defineMeshLayout(const std::vector&, + const std::vector&, + const std::vector&, const std::pair&, const std::vector&, bool, diff --git a/tests/archetypes/energy_dist.cpp b/tests/archetypes/energy_dist.cpp index 2f454cf95..d0c15c19d 100644 --- a/tests/archetypes/energy_dist.cpp +++ b/tests/archetypes/energy_dist.cpp @@ -24,7 +24,7 @@ template struct Caller { Caller(const EnrgDist& dist) : dist { dist } {} - Inline void operator()(index_t) const { + Inline void operator()(prtlidx_t) const { vec_t vp { ZERO }; coord_t xp { ZERO }; for (dim_t d { 0u }; d < D; ++d) { @@ -42,7 +42,7 @@ struct Caller { }; template -void testEnergyDist(const std::vector& res, +void testEnergyDist(const std::vector& res, const boundaries_t& ext, const std::map& params = {}) { raise::ErrorIf(res.size() != M::Dim, "res.size() != M::Dim", HERE); diff --git a/tests/archetypes/field_setter.cpp b/tests/archetypes/field_setter.cpp index c47b0f18a..b5c9b4490 100644 --- a/tests/archetypes/field_setter.cpp +++ b/tests/archetypes/field_setter.cpp @@ -33,7 +33,7 @@ struct ConstantFiller { auto main(int argc, char* argv[]) -> int { Kokkos::initialize(argc, argv); try { - constexpr std::size_t nx1 = 20; + constexpr ncells_t nx1 = 20; ndfield_t EM { "EM", nx1 + 2 * N_GHOSTS }; Minkowski metric { { nx1 }, { { -2.0, 2.0 } } }; ConstantFiller finit { 123.0 }; @@ -45,7 +45,7 @@ auto main(int argc, char* argv[]) -> int { finitializer); auto EM_h = Kokkos::create_mirror_view(EM); Kokkos::deep_copy(EM_h, EM); - for (std::size_t i1 = 0; i1 < nx1 + 2 * N_GHOSTS; ++i1) { + for (ncells_t i1 = 0; i1 < nx1 + 2 * N_GHOSTS; ++i1) { if ((i1 < N_GHOSTS) || (i1 >= nx1 + N_GHOSTS)) { for (const auto& comp : { em::ex1, em::ex2, em::ex3, em::bx1, em::bx2, em::bx3 }) { diff --git a/tests/archetypes/pgen.cpp b/tests/archetypes/pgen.cpp index 62e9fcce0..d95e9cf9c 100644 --- a/tests/archetypes/pgen.cpp +++ b/tests/archetypes/pgen.cpp @@ -88,7 +88,7 @@ struct CustomPgen { void CustomFieldOutput(const std::string&, ndfield_t&, - index_t, + uint32_t, timestep_t, simtime_t, const Domain&) {} diff --git a/tests/archetypes/powerlaw.cpp b/tests/archetypes/powerlaw.cpp index a74b01326..e7438dcad 100644 --- a/tests/archetypes/powerlaw.cpp +++ b/tests/archetypes/powerlaw.cpp @@ -28,7 +28,7 @@ struct Caller { : metric { metric } , dist { dist } {} - Inline void operator()(index_t) const { + Inline void operator()(prtlidx_t) const { vec_t vp { ZERO }; coord_t xp { ZERO }; for (dim_t d { 0u }; d < D; ++d) { @@ -63,7 +63,7 @@ struct Caller { }; template -void testEnergyDist(const std::vector& res, +void testEnergyDist(const std::vector& res, const boundaries_t& ext, const std::map& params = {}) { raise::ErrorIf(res.size() != M::Dim, "res.size() != M::Dim", HERE); diff --git a/tests/archetypes/spatial_dist.cpp b/tests/archetypes/spatial_dist.cpp index a3b75f08a..85e8e007a 100644 --- a/tests/archetypes/spatial_dist.cpp +++ b/tests/archetypes/spatial_dist.cpp @@ -27,7 +27,7 @@ struct Caller { : dist { dist } , metric { metric } {} - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { if constexpr (M::Dim == Dim::_2D) { coord_t x_Code { static_cast(i1), static_cast(i2) }; coord_t x_Sph { ZERO }; @@ -42,7 +42,7 @@ struct Caller { } } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { if constexpr (M::Dim == Dim::_3D) { coord_t x_Code { static_cast(i1), static_cast(i2), diff --git a/tests/framework/checkpoint-data.cpp b/tests/framework/checkpoint-data.cpp index 669e0a381..1b2aa6f6d 100644 --- a/tests/framework/checkpoint-data.cpp +++ b/tests/framework/checkpoint-data.cpp @@ -120,7 +120,7 @@ auto main(int argc, char* argv[]) -> int { // set em::ex1(i) = real_t(i) over all cells including ghost cells { auto em_h = Kokkos::create_mirror_view(local->fields.em); - for (std::size_t i { 0 }; i < n_all; ++i) { + for (ncells_t i { 0 }; i < n_all; ++i) { em_h(i, em::ex1) = static_cast(i); } Kokkos::deep_copy(local->fields.em, em_h); @@ -188,7 +188,7 @@ auto main(int argc, char* argv[]) -> int { { auto em_h = Kokkos::create_mirror_view(local->fields.em); Kokkos::deep_copy(em_h, local->fields.em); - for (std::size_t i { 0 }; i < exp_n_all; ++i) { + for (ncells_t i { 0 }; i < exp_n_all; ++i) { raise::ErrorIf( not cmp::AlmostEqual(em_h(i, em::ex1), static_cast(i)), fmt::format("em::ex1 mismatch at i=%lu: got %f, expected %f", diff --git a/tests/framework/comm-mpi.cpp b/tests/framework/comm-mpi.cpp index 662838e92..d9603c8c1 100644 --- a/tests/framework/comm-mpi.cpp +++ b/tests/framework/comm-mpi.cpp @@ -28,31 +28,31 @@ auto main(int argc, char* argv[]) -> int { "Fill", CreateRangePolicy({ 0, 0 }, { nx1 + 2 * N_GHOSTS, nx2 + 2 * N_GHOSTS }), - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { if ((i1 >= N_GHOSTS) and (i1 < N_GHOSTS + nx1) and (i2 >= N_GHOSTS) and (i2 < N_GHOSTS + nx2)) { - fld(i1, i2, 0) = static_cast(rank + 1) + 4.0; - fld(i1, i2, 1) = static_cast(rank + 1) + 12.0; - fld(i1, i2, 2) = static_cast(rank + 1) + 20.0; + fld(i1, i2, 0) = static_cast(rank + 1 + 4.0); + fld(i1, i2, 1) = static_cast(rank + 1 + 12.0); + fld(i1, i2, 2) = static_cast(rank + 1 + 20.0); } }); { // send right, recv left - const int send_idx = (rank + 1) % size; - const int recv_idx = (rank - 1 + size) % size; - const unsigned int send_rank = (unsigned int)send_idx; - const unsigned int recv_rank = (unsigned int)recv_idx; + const int send_idx = (rank + 1) % size; + const int recv_idx = (rank - 1 + size) % size; + const int send_rank = send_idx; + const int recv_rank = recv_idx; - const std::vector send_slice { + const std::vector send_slice { { nx1, nx1 + N_GHOSTS }, { N_GHOSTS, nx2 + N_GHOSTS } }; - const std::vector recv_slice { + const std::vector recv_slice { { 0, N_GHOSTS }, { N_GHOSTS, nx2 + N_GHOSTS } }; - const range_tuple_t comp_slice { 0, 3 }; + const cell_range_t comp_slice { 0, 3 }; comm::CommunicateField((unsigned int)(rank), fld, fld, @@ -67,20 +67,20 @@ auto main(int argc, char* argv[]) -> int { } { // recv right, send left - const int send_idx = (rank - 1 + size) % size; - const int recv_idx = (rank + 1) % size; - const unsigned int send_rank = (unsigned int)send_idx; - const unsigned int recv_rank = (unsigned int)recv_idx; + const int send_idx = (rank - 1 + size) % size; + const int recv_idx = (rank + 1) % size; + const int send_rank = send_idx; + const int recv_rank = recv_idx; - const std::vector send_slice { + const std::vector send_slice { { N_GHOSTS, N_GHOSTS + 2 }, { N_GHOSTS, nx2 + N_GHOSTS } }; - const std::vector recv_slice { + const std::vector recv_slice { { nx1 + N_GHOSTS, nx1 + 2 * N_GHOSTS }, { N_GHOSTS, nx2 + N_GHOSTS } }; - const range_tuple_t comp_slice { 0, 3 }; + const cell_range_t comp_slice { 0, 3 }; comm::CommunicateField((unsigned int)(rank), fld, fld, @@ -101,7 +101,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "Check", CreateRangePolicy({ N_GHOSTS }, { nx2 + N_GHOSTS }), - Lambda(index_t i2) { + Lambda(cellidx_t i2) { for (auto i1 { 0u }; i1 < N_GHOSTS; ++i1) { if (fld(i1, i2, 0) != left_expect + 4.0) { raise::KernelError(HERE, "Left boundary not correct for #0"); @@ -131,7 +131,7 @@ auto main(int argc, char* argv[]) -> int { "Carve", CreateRangePolicy({ 0, 0 }, { nx1 + 2 * N_GHOSTS, nx2 + 2 * N_GHOSTS }), - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { if (((i1 >= N_GHOSTS) and (i1 < 2 * N_GHOSTS)) or ((i1 >= nx1) and (i1 < nx1 + N_GHOSTS))) { fld(i1, i2, 0) = ZERO; @@ -142,20 +142,20 @@ auto main(int argc, char* argv[]) -> int { { // send right, recv left - const int send_idx = (rank + 1) % size; - const int recv_idx = (rank - 1 + size) % size; - const unsigned int send_rank = (unsigned int)send_idx; - const unsigned int recv_rank = (unsigned int)recv_idx; + const int send_idx = (rank + 1) % size; + const int recv_idx = (rank - 1 + size) % size; + const int send_rank = send_idx; + const int recv_rank = recv_idx; - const std::vector send_slice { + const std::vector send_slice { { nx1 + N_GHOSTS, nx1 + 2 * N_GHOSTS }, { N_GHOSTS, nx2 + N_GHOSTS } }; - const std::vector recv_slice { + const std::vector recv_slice { { N_GHOSTS, 2 * N_GHOSTS }, { N_GHOSTS, nx2 + N_GHOSTS } }; - const range_tuple_t comp_slice { 0, 3 }; + const cell_range_t comp_slice { 0, 3 }; comm::CommunicateField((unsigned int)(rank), fld, fld, @@ -170,20 +170,20 @@ auto main(int argc, char* argv[]) -> int { } { // recv right, send left - const int send_idx = (rank - 1 + size) % size; - const int recv_idx = (rank + 1) % size; - const unsigned int send_rank = (unsigned int)send_idx; - const unsigned int recv_rank = (unsigned int)recv_idx; + const int send_idx = (rank - 1 + size) % size; + const int recv_idx = (rank + 1) % size; + const int send_rank = send_idx; + const int recv_rank = recv_idx; - const std::vector send_slice { + const std::vector send_slice { { 0, N_GHOSTS }, { N_GHOSTS, nx2 + N_GHOSTS } }; - const std::vector recv_slice { + const std::vector recv_slice { { nx1, nx1 + N_GHOSTS }, { N_GHOSTS, nx2 + N_GHOSTS } }; - const range_tuple_t comp_slice { 0, 3 }; + const cell_range_t comp_slice { 0, 3 }; comm::CommunicateField((unsigned int)(rank), fld, fld, @@ -202,7 +202,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "Check", CreateRangePolicy({ N_GHOSTS }, { nx2 + N_GHOSTS }), - Lambda(index_t i2) { + Lambda(cellidx_t i2) { for (auto i1 { N_GHOSTS }; i1 < 2 * N_GHOSTS; ++i1) { if (fld(i1, i2, 0) != expect + 4.0) { raise::KernelError(HERE, "Left boundary not correct for #0"); diff --git a/tests/framework/comm-nompi.cpp b/tests/framework/comm-nompi.cpp index 8c9af8072..a6128a1f7 100644 --- a/tests/framework/comm-nompi.cpp +++ b/tests/framework/comm-nompi.cpp @@ -12,7 +12,7 @@ auto main(int argc, char* argv[]) -> int { using namespace ntt; GlobalInitialize(argc, argv); try { - const std::size_t nx1 = 15, nx2 = 15; + const ncells_t nx1 = 15, nx2 = 15; ndfield_t fld { "fld", nx1 + 2 * N_GHOSTS, nx2 + 2 * N_GHOSTS }; ndfield_t buff { "buff", nx1 + 2 * N_GHOSTS, nx2 + 2 * N_GHOSTS }; @@ -20,7 +20,7 @@ auto main(int argc, char* argv[]) -> int { "Fill", CreateRangePolicy({ 0, 0 }, { nx1 + 2 * N_GHOSTS, nx2 + 2 * N_GHOSTS }), - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { if ((i1 >= 2 * N_GHOSTS) and (i1 < nx1) and (i2 >= 2 * N_GHOSTS) and (i2 < nx2)) { fld(i1, i2, 0) = 4.0; @@ -40,42 +40,39 @@ auto main(int argc, char* argv[]) -> int { }); Kokkos::deep_copy(buff, ZERO); - const auto send_slice = std::vector { + const auto send_slice = std::vector { { nx1 + N_GHOSTS, nx1 + 2 * N_GHOSTS }, { nx2 + N_GHOSTS, nx2 + 2 * N_GHOSTS } }; - const auto recv_slice = std::vector { + const auto recv_slice = std::vector { { N_GHOSTS, 2 * N_GHOSTS }, { N_GHOSTS, 2 * N_GHOSTS } }; - const auto comp_slice = range_tuple_t(cur::jx1, cur::jx3 + 1); + const auto comp_slice = cell_range_t(cur::jx1, cur::jx3 + 1); const auto i_min = [](in c) { switch (c) { case in::x1: - return (std::size_t)N_GHOSTS; case in::x2: - return (std::size_t)N_GHOSTS; case in::x3: - return (std::size_t)N_GHOSTS; + return N_GHOSTS; } - return (std::size_t)0; + return 0u; }; const auto i_max = [](in c) { switch (c) { case in::x1: - return nx1 + N_GHOSTS; case in::x2: return nx2 + N_GHOSTS; case in::x3: - return (std::size_t)0; + return 0u; } - return (std::size_t)0; + return 0u; }; const in components[] = { in::x1, in::x2, in::x3 }; for (auto& direction : dir::Directions::all) { - auto send_slice = std::vector {}; - auto recv_slice = std::vector {}; + auto send_slice = std::vector {}; + auto recv_slice = std::vector {}; for (std::size_t d { 0 }; d < direction.size(); ++d) { const auto c = components[d]; const auto dir = direction[d]; @@ -110,7 +107,7 @@ auto main(int argc, char* argv[]) -> int { "AddBuffers", CreateRangePolicy({ 0, 0 }, { nx1 + 2 * N_GHOSTS, nx2 + 2 * N_GHOSTS }), - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { for (auto k { 0 }; k < 3; ++k) { fld(i1, i2, k) += buff(i1, i2, k); } @@ -120,7 +117,7 @@ auto main(int argc, char* argv[]) -> int { "Check", CreateRangePolicy({ 0, 0 }, { nx1 + 2 * N_GHOSTS, nx2 + 2 * N_GHOSTS }), - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { if (fld(i1, i2, 0) != 4.0) { raise::KernelError(HERE, "fld0 wrong after comm"); } diff --git a/tests/framework/fields.cpp b/tests/framework/fields.cpp index f86277197..d38ba5ebb 100644 --- a/tests/framework/fields.cpp +++ b/tests/framework/fields.cpp @@ -9,7 +9,7 @@ #include template -void testFields(const std::vector& res) { +void testFields(const std::vector& res) { using namespace ntt; raise::ErrorIf(res.size() != D, "Resolution vector has wrong size", HERE); auto f = Fields { res }; diff --git a/tests/framework/grid_mesh.cpp b/tests/framework/grid_mesh.cpp index 79960ace3..02240b220 100644 --- a/tests/framework/grid_mesh.cpp +++ b/tests/framework/grid_mesh.cpp @@ -17,7 +17,7 @@ auto main(int argc, char* argv[]) -> int { using namespace metric; GlobalInitialize(argc, argv); try { - const auto res = std::vector { 10, 10, 10 }; + const auto res = std::vector { 10, 10, 10 }; const auto ext = boundaries_t { { -1.0, 1.0 }, { -1.0, 1.0 }, diff --git a/tests/framework/metadomain.cpp b/tests/framework/metadomain.cpp index 005e442c2..82c9e9204 100644 --- a/tests/framework/metadomain.cpp +++ b/tests/framework/metadomain.cpp @@ -40,7 +40,7 @@ auto main(int argc, char* argv[]) -> int { 4u, { -1, -1 }, res, extent, fldsbc, prtlbc, params, {} }; - std::size_t nx1 { 0 }, nx2 { 0 }; + ncells_t nx1 { 0 }, nx2 { 0 }; raise::ErrorIf(metadomain.mesh().n_active() != res, "Mesh::n_active() failed", HERE); diff --git a/tests/framework/parameters.cpp b/tests/framework/parameters.cpp index f4b318007..82821b899 100644 --- a/tests/framework/parameters.cpp +++ b/tests/framework/parameters.cpp @@ -322,7 +322,7 @@ auto main(int argc, char* argv[]) -> int { assert_equal(species[0].label(), "e-", "species[0].label"); assert_equal(species[0].mass(), 1.0f, "species[0].mass"); assert_equal(species[0].charge(), -1.0f, "species[0].charge"); - assert_equal(species[0].maxnpart(), 100, "species[0].maxnpart"); + assert_equal(species[0].maxnpart(), 100, "species[0].maxnpart"); assert_equal(species[0].clearing_interval(), static_cast(50u), "species[0].clearing_interval"); diff --git a/tests/framework/particles.cpp b/tests/framework/particles.cpp index 55ced3a38..94716496d 100644 --- a/tests/framework/particles.cpp +++ b/tests/framework/particles.cpp @@ -14,7 +14,7 @@ void testParticles( const std::string& label, float m, float ch, - std::size_t maxnpart, + npart_t maxnpart, timestep_t clearing_interval, timestep_t spatial_sorting_interval, ntt::ParticlePusherFlags pusher, diff --git a/tests/framework/particles_sort.cpp b/tests/framework/particles_sort.cpp index 5af7e98c2..1ba10d828 100644 --- a/tests/framework/particles_sort.cpp +++ b/tests/framework/particles_sort.cpp @@ -40,7 +40,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "InitParticles", prtls.maxnpart(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { if (p < 66u) { tag_p(p) = (p % 10u == 0u) ? ntt::ParticleTag::dead : ntt::ParticleTag::alive; @@ -137,7 +137,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "InitParticles", prtls.maxnpart(), - Lambda(index_t p) { + Lambda(prtlidx_t p) { if (p < 66u) { tag_p(p) = (p % 10u == 0u) ? ntt::ParticleTag::dead : ntt::ParticleTag::alive; diff --git a/tests/global/global.cpp b/tests/global/global.cpp index f86290e36..df5123cae 100644 --- a/tests/global/global.cpp +++ b/tests/global/global.cpp @@ -43,8 +43,10 @@ auto main(int argc, char* argv[]) -> int { static_assert(std::is_same_v, tuple_t>); static_assert(std::is_same_v, tuple_t>); - static_assert(std::is_same_v>); - static_assert(std::is_same_v); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v); + static_assert(std::is_same_v); try { GlobalInitialize(argc, argv); @@ -52,7 +54,7 @@ auto main(int argc, char* argv[]) -> int { raise::ErrorIf(not Kokkos::is_initialized(), "Kokkos was not initialized", HERE); } catch (std::exception& err) { - std::cerr << err.what() << std::endl; + std::cerr << err.what() << '\n'; GlobalFinalize(); return 1; } diff --git a/tests/global/kokkos_aliases.cpp b/tests/global/kokkos_aliases.cpp index efc683e19..8357c0e1b 100644 --- a/tests/global/kokkos_aliases.cpp +++ b/tests/global/kokkos_aliases.cpp @@ -78,7 +78,7 @@ auto main(int argc, char* argv[]) -> int { } catch (std::exception& err) { - std::cerr << err.what() << std::endl; + std::cerr << err.what() << '\n'; GlobalFinalize(); return 1; } diff --git a/tests/global/sorting.cpp b/tests/global/sorting.cpp index a852f754c..b7513b6e7 100644 --- a/tests/global/sorting.cpp +++ b/tests/global/sorting.cpp @@ -105,7 +105,7 @@ auto main(int argc, char* argv[]) -> int { } }); } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; ntt::GlobalFinalize(); return 1; } diff --git a/tests/global/tiling.cpp b/tests/global/tiling.cpp index 67c84f573..2f926ce28 100644 --- a/tests/global/tiling.cpp +++ b/tests/global/tiling.cpp @@ -8,7 +8,7 @@ #include template -Inline void CheckValue(index_t, +Inline void CheckValue(prtlidx_t, const array_t&, const array_t&, const array_t&, @@ -21,7 +21,7 @@ Inline void CheckValue(index_t, ncells_t); template <> -Inline void CheckValue(index_t p, +Inline void CheckValue(prtlidx_t p, const array_t& i1, const array_t&, const array_t&, @@ -45,7 +45,7 @@ Inline void CheckValue(index_t p, } template <> -Inline void CheckValue(index_t p, +Inline void CheckValue(prtlidx_t p, const array_t& i1, const array_t& i2, const array_t&, @@ -70,7 +70,7 @@ Inline void CheckValue(index_t p, } template <> -Inline void CheckValue(index_t p, +Inline void CheckValue(prtlidx_t p, const array_t& i1, const array_t& i2, const array_t& i3, @@ -129,7 +129,7 @@ void test_tiling(const array_t& i1, Kokkos::parallel_for( "Checking", npart, - Lambda(index_t p) { + Lambda(prtlidx_t p) { CheckValue(p, i1, i2, i3, tag, tile_indices, nt1, nt2, nt3, ntiles, ts); }); @@ -137,7 +137,7 @@ void test_tiling(const array_t& i1, Kokkos::parallel_reduce( "CountAliveInTiles", ntiles, - Lambda(index_t t, npart_t & count) { count += num_ppt(t); }, + Lambda(prtlidx_t t, npart_t & count) { count += num_ppt(t); }, tot_alive); raise::ErrorIf(tot_alive != npart - ndead, "Error in counting particles per tile", @@ -168,7 +168,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "Initialize", npart, - Lambda(index_t p) { + Lambda(prtlidx_t p) { auto gen = random_pool.get_state(); i1(p) = static_cast(gen.urand(0u, nx1)); i2(p) = static_cast(gen.urand(0u, nx2)); @@ -216,7 +216,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "Initialize", npart, - Lambda(index_t p) { + Lambda(prtlidx_t p) { const auto cell_idx = p % ncells; i1(p) = static_cast(cell_idx) % static_cast(nx1); i2(p) = static_cast(cell_idx) / static_cast(nx1); @@ -236,7 +236,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "CheckOutOfBounds", npart, - Lambda(index_t p) { + Lambda(prtlidx_t p) { const auto tile_idx = tile_indices(p); const auto t1 = tile_idx / nt2; const auto t2 = tile_idx % nt2; diff --git a/tests/global/traits_pgen.cpp b/tests/global/traits_pgen.cpp index 1e87e233b..38daedd14 100644 --- a/tests/global/traits_pgen.cpp +++ b/tests/global/traits_pgen.cpp @@ -143,7 +143,7 @@ struct WithCustomFieldOutput { void CustomFieldOutput(const std::string&, ndfield_t&, - index_t, + uint32_t, timestep_t, simtime_t, const DummyDomain&) {} diff --git a/tests/global/traits_policies.cpp b/tests/global/traits_policies.cpp index 217b687ad..5f5a83f9f 100644 --- a/tests/global/traits_policies.cpp +++ b/tests/global/traits_policies.cpp @@ -118,7 +118,7 @@ static_assert(not ExtFieldsPolicyClass); // --- CustomParticleUpdatePolicyClass with a real updater --- struct ValidCustomPrtlUpdate { - void operator()(index_t, + void operator()(prtlidx_t, const kernel::sr::PusherContext&, const kernel::sr::PusherBoundaries&, const ntt::ParticleArrays&, @@ -129,7 +129,7 @@ static_assert(CustomParticleUpdatePolicyClass // Wrong signature: missing the metric argument struct BadCustomPrtlUpdate { - void operator()(index_t, + void operator()(prtlidx_t, const kernel::sr::PusherContext&, const kernel::sr::PusherBoundaries&, const ntt::ParticleArrays&) const {} diff --git a/tests/kernels/ampere_mink.cpp b/tests/kernels/ampere_mink.cpp index 181946613..fd74376ad 100644 --- a/tests/kernels/ampere_mink.cpp +++ b/tests/kernels/ampere_mink.cpp @@ -32,10 +32,10 @@ Inline auto equal(real_t a, real_t b, const char* msg, real_t acc) -> bool { } template -void testAmpere(const std::vector&); +void testAmpere(const std::vector&); template <> -void testAmpere(const std::vector& res) { +void testAmpere(const std::vector& res) { errorIf(res.size() != 1, "res.size() != 1"); const real_t sx = constant::TWO_PI; @@ -52,7 +52,7 @@ void testAmpere(const std::vector& res) { Kokkos::parallel_for( "init 1D", range_ext, - Lambda(index_t i1) { + Lambda(cellidx_t i1) { const coord_t x_Code { COORD(i1) + HALF }; coord_t x_Cart { ZERO }; metric.template convert_xyz(x_Code, x_Cart); @@ -74,7 +74,7 @@ void testAmpere(const std::vector& res) { Kokkos::parallel_reduce( "check ampere 1D", range, - Lambda(index_t i1, unsigned long& wrongs) { + Lambda(cellidx_t i1, unsigned long& wrongs) { const coord_t x_Code { COORD(i1) }; coord_t x_Cart { ZERO }; metric.template convert_xyz(x_Code, x_Cart); @@ -100,7 +100,7 @@ void testAmpere(const std::vector& res) { } template <> -void testAmpere(const std::vector& res) { +void testAmpere(const std::vector& res) { errorIf(res.size() != 2, "res.size() != 2"); using namespace ntt; @@ -110,14 +110,14 @@ void testAmpere(const std::vector& res) { res, { { ZERO, sx }, { ZERO, sy } } }; - auto emfield = ndfield_t { "emfield", - res[0] + 2 * N_GHOSTS, - res[1] + 2 * N_GHOSTS }; - const std::size_t i1min = N_GHOSTS, i1max = res[0] + N_GHOSTS; - const std::size_t i2min = N_GHOSTS, i2max = res[1] + N_GHOSTS; - const auto range = CreateRangePolicy({ i1min, i2min }, - { i1max, i2max }); - const auto range_ext = CreateRangePolicy( + auto emfield = ndfield_t { "emfield", + res[0] + 2 * N_GHOSTS, + res[1] + 2 * N_GHOSTS }; + const ncells_t i1min = N_GHOSTS, i1max = res[0] + N_GHOSTS; + const ncells_t i2min = N_GHOSTS, i2max = res[1] + N_GHOSTS; + const auto range = CreateRangePolicy({ i1min, i2min }, + { i1max, i2max }); + const auto range_ext = CreateRangePolicy( { 0, 0 }, { res[0] + 2 * N_GHOSTS, res[1] + 2 * N_GHOSTS }); const auto dx = (metric.x1_max - metric.x1_min) / (real_t)metric.nx1; @@ -126,7 +126,7 @@ void testAmpere(const std::vector& res) { Kokkos::parallel_for( "init 2D", range_ext, - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { const coord_t x_Code_p0 { COORD(i1) + HALF, COORD(i2) }; const coord_t x_Code_0p { COORD(i1), COORD(i2) + HALF }; const coord_t x_Code_pp { COORD(i1) + HALF, COORD(i2) + HALF }; @@ -163,7 +163,7 @@ void testAmpere(const std::vector& res) { Kokkos::parallel_reduce( "check ampere 2D", range, - Lambda(index_t i1, index_t i2, unsigned long& wrongs) { + Lambda(cellidx_t i1, cellidx_t i2, unsigned long& wrongs) { const coord_t x_Code_00 { COORD(i1), COORD(i2) }; const coord_t x_Code_p0 { COORD(i1) + HALF, COORD(i2) }; const coord_t x_Code_0p { COORD(i1), COORD(i2) + HALF }; @@ -205,7 +205,7 @@ void testAmpere(const std::vector& res) { } template <> -void testAmpere(const std::vector& res) { +void testAmpere(const std::vector& res) { errorIf(res.size() != 3, "res.size() != 3"); using namespace ntt; @@ -215,16 +215,16 @@ void testAmpere(const std::vector& res) { res, { { ZERO, sx }, { ZERO, sy }, { ZERO, sz } } }; - auto emfield = ndfield_t { "emfield", - res[0] + 2 * N_GHOSTS, - res[1] + 2 * N_GHOSTS, - res[2] + 2 * N_GHOSTS }; - const std::size_t i1min = N_GHOSTS, i1max = res[0] + N_GHOSTS; - const std::size_t i2min = N_GHOSTS, i2max = res[1] + N_GHOSTS; - const std::size_t i3min = N_GHOSTS, i3max = res[2] + N_GHOSTS; - const auto range = CreateRangePolicy({ i1min, i2min, i3min }, - { i1max, i2max, i3max }); - const auto range_ext = CreateRangePolicy( + auto emfield = ndfield_t { "emfield", + res[0] + 2 * N_GHOSTS, + res[1] + 2 * N_GHOSTS, + res[2] + 2 * N_GHOSTS }; + const ncells_t i1min = N_GHOSTS, i1max = res[0] + N_GHOSTS; + const ncells_t i2min = N_GHOSTS, i2max = res[1] + N_GHOSTS; + const ncells_t i3min = N_GHOSTS, i3max = res[2] + N_GHOSTS; + const auto range = CreateRangePolicy({ i1min, i2min, i3min }, + { i1max, i2max, i3max }); + const auto range_ext = CreateRangePolicy( { 0, 0, 0 }, { res[0] + 2 * N_GHOSTS, res[1] + 2 * N_GHOSTS, res[2] + 2 * N_GHOSTS }); const auto dx = (metric.x1_max - metric.x1_min) / (real_t)metric.nx1; @@ -233,7 +233,7 @@ void testAmpere(const std::vector& res) { Kokkos::parallel_for( "init 3D", range_ext, - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { const coord_t x_Code_0pp { COORD(i1), COORD(i2) + HALF, COORD(i3) + HALF }; @@ -287,7 +287,7 @@ void testAmpere(const std::vector& res) { Kokkos::parallel_reduce( "check ampere 3D", range, - Lambda(index_t i1, index_t i2, index_t i3, unsigned long& wrongs) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3, unsigned long& wrongs) { const coord_t x_Code_p00 { COORD(i1) + HALF, COORD(i2), COORD(i3) }; const coord_t x_Code_0p0 { COORD(i1), COORD(i2) + HALF, COORD(i3) }; const coord_t x_Code_00p { COORD(i1), COORD(i2), COORD(i3) + HALF }; @@ -361,7 +361,7 @@ auto main(int argc, char* argv[]) -> int { testAmpere({ 32, 64, 32 }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/custom_prtl_update.cpp b/tests/kernels/custom_prtl_update.cpp index 2b2aae8d0..2d2cf5dab 100644 --- a/tests/kernels/custom_prtl_update.cpp +++ b/tests/kernels/custom_prtl_update.cpp @@ -38,7 +38,7 @@ auto equal(real_t a, real_t b, const std::string& msg) -> bool { } template -void put_value(array_t& arr, T v, index_t p) { +void put_value(array_t& arr, T v, prtlidx_t p) { auto h = Kokkos::create_mirror_view(arr); Kokkos::deep_copy(h, arr); h(p) = v; @@ -47,7 +47,7 @@ void put_value(array_t& arr, T v, index_t p) { template struct TestCustomPrtlUpdate { - Inline void operator()(index_t p, + Inline void operator()(prtlidx_t p, const kernel::sr::PusherContext& ctx, const kernel::sr::PusherBoundaries&, const ntt::ParticleArrays& particles, @@ -101,7 +101,7 @@ struct TestCustomPrtlUpdate { }; template -void testCustomPrtlUpdate(const std::vector& res, +void testCustomPrtlUpdate(const std::vector& res, const boundaries_t& ext, const std::map& params = {}) { @@ -353,20 +353,20 @@ auto main(int argc, char* argv[]) -> int { try { using namespace ntt; - const std::vector res1d { 50 }; - const boundaries_t ext1d { - { 0.0, 1000.0 } + const std::vector res1d { 50 }; + const boundaries_t ext1d { + { 0.0, 1000.0 } }; - const std::vector res2d { 30, 20 }; - const boundaries_t ext2d { - { -15.0, 15.0 }, - { -10.0, 10.0 } + const std::vector res2d { 30, 20 }; + const boundaries_t ext2d { + { -15.0, 15.0 }, + { -10.0, 10.0 } }; - const std::vector res3d { 10, 10, 10 }; - const boundaries_t ext3d { - { 0.0, 1.0 }, - { 0.0, 1.0 }, - { 0.0, 1.0 } + const std::vector res3d { 10, 10, 10 }; + const boundaries_t ext3d { + { 0.0, 1.0 }, + { 0.0, 1.0 }, + { 0.0, 1.0 } }; testCustomPrtlUpdate>(res1d, ext1d, {}); diff --git a/tests/kernels/deposit.cpp b/tests/kernels/deposit.cpp index b30aff409..24f544202 100644 --- a/tests/kernels/deposit.cpp +++ b/tests/kernels/deposit.cpp @@ -47,7 +47,7 @@ void put_value(const array_t& arr, T value, int i) { } template -void testDeposit(const std::vector& res, +void testDeposit(const std::vector& res, const boundaries_t& ext, const std::map& params, const real_t eps) { diff --git a/tests/kernels/digital_filter.cpp b/tests/kernels/digital_filter.cpp index 19f9d5712..e833b23f6 100644 --- a/tests/kernels/digital_filter.cpp +++ b/tests/kernels/digital_filter.cpp @@ -29,7 +29,7 @@ void errorIf(bool condition, const std::string& message) { } template -void testFilter(const std::vector& res, +void testFilter(const std::vector& res, const boundaries_t& ext, const std::map& params = {}) { static_assert(M::Dim == 2); @@ -59,7 +59,7 @@ void testFilter(const std::vector& res, ndfield_t J { "J", nx1 + 2 * N_GHOSTS, nx2 + 2 * N_GHOSTS }; ndfield_t Jbuff { "Jbuff", nx1 + 2 * N_GHOSTS, nx2 + 2 * N_GHOSTS }; - tuple_t size; + tuple_t size; size[0] = nx1; size[1] = nx2; auto J_h = Kokkos::create_mirror_view(J); @@ -79,17 +79,17 @@ void testFilter(const std::vector& res, Kokkos::parallel_reduce( "SumJx1", range, - Lambda(index_t i, index_t j, real_t & sum) { sum += J(i, j, cur::jx1); }, + Lambda(cellidx_t i, cellidx_t j, real_t & sum) { sum += J(i, j, cur::jx1); }, SumJx1); Kokkos::parallel_reduce( "SumJx2", range, - Lambda(index_t i, index_t j, real_t & sum) { sum += J(i, j, cur::jx2); }, + Lambda(cellidx_t i, cellidx_t j, real_t & sum) { sum += J(i, j, cur::jx2); }, SumJx2); Kokkos::parallel_reduce( "SumJx3", range, - Lambda(index_t i, index_t j, real_t & sum) { sum += J(i, j, cur::jx3); }, + Lambda(cellidx_t i, cellidx_t j, real_t & sum) { sum += J(i, j, cur::jx3); }, SumJx3); Kokkos::deep_copy(J_h, J); @@ -134,7 +134,7 @@ auto main(int argc, char* argv[]) -> int { using namespace ntt; using namespace metric; - const auto res = std::vector { 10, 10 }; + const auto res = std::vector { 10, 10 }; const auto r_extent = boundaries_t { { 0.0, 100.0 } }; @@ -175,7 +175,7 @@ auto main(int argc, char* argv[]) -> int { }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/ext_force.cpp b/tests/kernels/ext_force.cpp index 3d1ee76b8..69d773d10 100644 --- a/tests/kernels/ext_force.cpp +++ b/tests/kernels/ext_force.cpp @@ -44,7 +44,7 @@ void check_value(unsigned int t, } template -void put_value(array_t& arr, T v, index_t p) { +void put_value(array_t& arr, T v, prtlidx_t p) { auto h = Kokkos::create_mirror_view(arr); Kokkos::deep_copy(h, arr); h(p) = v; @@ -71,7 +71,7 @@ struct Force { }; template -void testPusher(const std::vector& res) { +void testPusher(const std::vector& res) { static_assert(M::Dim == 3); raise::ErrorIf(res.size() != M::Dim, "res.size() != M::Dim", HERE); @@ -104,7 +104,7 @@ void testPusher(const std::vector& res) { Kokkos::parallel_for( "init 3D", range_ext, - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { emfield(i1, i2, i3, em::ex1) = ZERO; emfield(i1, i2, i3, em::ex2) = ZERO; emfield(i1, i2, i3, em::ex3) = ZERO; diff --git a/tests/kernels/faraday_mink.cpp b/tests/kernels/faraday_mink.cpp index fb0ad9c76..64a25196b 100644 --- a/tests/kernels/faraday_mink.cpp +++ b/tests/kernels/faraday_mink.cpp @@ -1,6 +1,5 @@ #include "kernels/faraday_mink.hpp" -#include "enums.h" #include "global.h" #include "arch/kokkos_aliases.h" @@ -33,10 +32,10 @@ Inline auto equal(real_t a, real_t b, const char* msg, real_t acc) -> bool { } template -void testFaraday(const std::vector&); +void testFaraday(const std::vector&); template <> -void testFaraday(const std::vector& res) { +void testFaraday(const std::vector& res) { errorIf(res.size() != 1, "res.size() != 1"); using namespace ntt; @@ -55,7 +54,7 @@ void testFaraday(const std::vector& res) { Kokkos::parallel_for( "init 1D", range_ext, - Lambda(index_t i1) { + Lambda(cellidx_t i1) { const coord_t x_Code { COORD(i1) }; coord_t x_Cart { ZERO }; metric.template convert_xyz(x_Code, x_Cart); @@ -77,7 +76,7 @@ void testFaraday(const std::vector& res) { Kokkos::parallel_reduce( "check faraday 1D", range, - Lambda(index_t i1, unsigned long& wrongs) { + Lambda(cellidx_t i1, unsigned long& wrongs) { const coord_t x_Code { COORD(i1) + HALF }; coord_t x_Cart { ZERO }; metric.template convert_xyz(x_Code, x_Cart); @@ -103,7 +102,7 @@ void testFaraday(const std::vector& res) { } template <> -void testFaraday(const std::vector& res) { +void testFaraday(const std::vector& res) { errorIf(res.size() != 2, "res.size() != 2"); const real_t sx = constant::TWO_PI, sy = 4.0 * constant::PI; @@ -111,14 +110,14 @@ void testFaraday(const std::vector& res) { res, { { ZERO, sx }, { ZERO, sy } } }; - auto emfield = ndfield_t { "emfield", - res[0] + 2 * N_GHOSTS, - res[1] + 2 * N_GHOSTS }; - const std::size_t i1min = N_GHOSTS, i1max = res[0] + N_GHOSTS; - const std::size_t i2min = N_GHOSTS, i2max = res[1] + N_GHOSTS; - const auto range = CreateRangePolicy({ i1min, i2min }, - { i1max, i2max }); - const auto range_ext = CreateRangePolicy( + auto emfield = ndfield_t { "emfield", + res[0] + 2 * N_GHOSTS, + res[1] + 2 * N_GHOSTS }; + const ncells_t i1min = N_GHOSTS, i1max = res[0] + N_GHOSTS; + const ncells_t i2min = N_GHOSTS, i2max = res[1] + N_GHOSTS; + const auto range = CreateRangePolicy({ i1min, i2min }, + { i1max, i2max }); + const auto range_ext = CreateRangePolicy( { 0, 0 }, { res[0] + 2 * N_GHOSTS, res[1] + 2 * N_GHOSTS }); const auto dx = (metric.x1_max - metric.x1_min) / (real_t)metric.nx1; @@ -127,7 +126,7 @@ void testFaraday(const std::vector& res) { Kokkos::parallel_for( "init 2D", range_ext, - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { const coord_t x_Code_00 { COORD(i1), COORD(i2) }; const coord_t x_Code_p0 { COORD(i1) + HALF, COORD(i2) }; const coord_t x_Code_0p { COORD(i1), COORD(i2) + HALF }; @@ -162,7 +161,7 @@ void testFaraday(const std::vector& res) { Kokkos::parallel_reduce( "check faraday 2D", range, - Lambda(index_t i1, index_t i2, unsigned long& wrongs) { + Lambda(cellidx_t i1, cellidx_t i2, unsigned long& wrongs) { const coord_t x_Code_p0 { COORD(i1) + HALF, COORD(i2) }; const coord_t x_Code_0p { COORD(i1), COORD(i2) + HALF }; const coord_t x_Code_pp { COORD(i1) + HALF, COORD(i2) + HALF }; @@ -205,7 +204,7 @@ void testFaraday(const std::vector& res) { } template <> -void testFaraday(const std::vector& res) { +void testFaraday(const std::vector& res) { errorIf(res.size() != 3, "res.size() != 3"); using namespace ntt; @@ -215,16 +214,16 @@ void testFaraday(const std::vector& res) { res, { { ZERO, sx }, { ZERO, sy }, { ZERO, sz } } }; - auto emfield = ndfield_t { "emfield", - res[0] + 2 * N_GHOSTS, - res[1] + 2 * N_GHOSTS, - res[2] + 2 * N_GHOSTS }; - const std::size_t i1min = N_GHOSTS, i1max = res[0] + N_GHOSTS; - const std::size_t i2min = N_GHOSTS, i2max = res[1] + N_GHOSTS; - const std::size_t i3min = N_GHOSTS, i3max = res[2] + N_GHOSTS; - const auto range = CreateRangePolicy({ i1min, i2min, i3min }, - { i1max, i2max, i3max }); - const auto range_ext = CreateRangePolicy( + auto emfield = ndfield_t { "emfield", + res[0] + 2 * N_GHOSTS, + res[1] + 2 * N_GHOSTS, + res[2] + 2 * N_GHOSTS }; + const ncells_t i1min = N_GHOSTS, i1max = res[0] + N_GHOSTS; + const ncells_t i2min = N_GHOSTS, i2max = res[1] + N_GHOSTS; + const ncells_t i3min = N_GHOSTS, i3max = res[2] + N_GHOSTS; + const auto range = CreateRangePolicy({ i1min, i2min, i3min }, + { i1max, i2max, i3max }); + const auto range_ext = CreateRangePolicy( { 0, 0, 0 }, { res[0] + 2 * N_GHOSTS, res[1] + 2 * N_GHOSTS, res[2] + 2 * N_GHOSTS }); const auto dx = (metric.x1_max - metric.x1_min) / (real_t)metric.nx1; @@ -233,7 +232,7 @@ void testFaraday(const std::vector& res) { Kokkos::parallel_for( "init 3D", range_ext, - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { const coord_t x_Code_p00 { COORD(i1) + HALF, COORD(i2), COORD(i3) }; const coord_t x_Code_0p0 { COORD(i1), COORD(i2) + HALF, COORD(i3) }; const coord_t x_Code_00p { COORD(i1), COORD(i2), COORD(i3) + HALF }; @@ -272,7 +271,7 @@ void testFaraday(const std::vector& res) { Kokkos::parallel_reduce( "check faraday 3D", range, - Lambda(index_t i1, index_t i2, index_t i3, unsigned long& wrongs) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3, unsigned long& wrongs) { const coord_t x_Code_0pp { COORD(i1), COORD(i2) + HALF, COORD(i3) + HALF }; @@ -338,7 +337,7 @@ auto main(int argc, char* argv[]) -> int { testFaraday({ 32, 64, 32 }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/fields_to_phys.cpp b/tests/kernels/fields_to_phys.cpp index 485183a7b..262f9dfc8 100644 --- a/tests/kernels/fields_to_phys.cpp +++ b/tests/kernels/fields_to_phys.cpp @@ -4,7 +4,6 @@ #include "global.h" #include "arch/kokkos_aliases.h" -#include "utils/comparators.h" #include "utils/numeric.h" #include "metrics/kerr_schild.h" @@ -20,7 +19,6 @@ #include #include #include -#include #include void errorIf(bool condition, const std::string& message) { @@ -33,7 +31,7 @@ using namespace ntt; using namespace metric; template -void testFlds2Phys(const std::vector& res, +void testFlds2Phys(const std::vector& res, const boundaries_t& ext, const std::map& params = {}) { static_assert(M::Dim == 2); @@ -175,7 +173,7 @@ auto main(int argc, char* argv[]) -> int { { { "a", 0.9 } }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/flds_bc.cpp b/tests/kernels/flds_bc.cpp index 101622226..143342e53 100644 --- a/tests/kernels/flds_bc.cpp +++ b/tests/kernels/flds_bc.cpp @@ -55,7 +55,7 @@ Inline auto equal(real_t a, real_t b, const char* msg, real_t acc) -> bool { } template -void testFldsBCs(const std::vector& res) { +void testFldsBCs(const std::vector& res) { errorIf(res.size() != (dim_t)D, "res.size() != D"); boundaries_t sx; for (const auto& r : res) { @@ -112,7 +112,7 @@ void testFldsBCs(const std::vector& res) { Kokkos::parallel_for( "MatchBoundaries_kernel", CreateRangePolicy({ N_GHOSTS }, { res[0] + N_GHOSTS }), - Lambda(index_t i1) { + Lambda(cellidx_t i1) { const auto x = static_cast(i1 - N_GHOSTS); const auto factor1 = math::tanh( FOUR * math::abs(x + HALF - xg_edge) / dx_abs); @@ -139,7 +139,7 @@ void testFldsBCs(const std::vector& res) { "MatchBoundaries_kernel", CreateRangePolicy({ N_GHOSTS, N_GHOSTS }, { res[0] + N_GHOSTS, res[1] + N_GHOSTS }), - Lambda(index_t i1, index_t i2) { + Lambda(cellidx_t i1, cellidx_t i2) { const auto x = static_cast(i1 - N_GHOSTS); const auto factor1 = math::tanh( FOUR * math::abs(x + HALF - xg_edge) / dx_abs); @@ -169,7 +169,7 @@ void testFldsBCs(const std::vector& res) { CreateRangePolicy( { N_GHOSTS, N_GHOSTS, N_GHOSTS }, { res[0] + N_GHOSTS, res[1] + N_GHOSTS, res[2] + N_GHOSTS }), - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { const auto x = static_cast(i1 - N_GHOSTS); const auto factor1 = math::tanh( FOUR * math::abs(x + HALF - xg_edge) / dx_abs); @@ -216,7 +216,7 @@ auto main(int argc, char* argv[]) -> int { testFldsBCs({ 14, 22, 15 }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/gca_pusher.cpp b/tests/kernels/gca_pusher.cpp index 7ec9bd769..ce2d4981a 100644 --- a/tests/kernels/gca_pusher.cpp +++ b/tests/kernels/gca_pusher.cpp @@ -45,7 +45,7 @@ void check_value(unsigned int t, } template -void put_value(array_t& arr, T v, index_t p) { +void put_value(array_t& arr, T v, prtlidx_t p) { auto h = Kokkos::create_mirror_view(arr); Kokkos::deep_copy(h, arr); h(p) = v; @@ -53,7 +53,7 @@ void put_value(array_t& arr, T v, index_t p) { } template -void testPusher(const std::vector& res) { +void testPusher(const std::vector& res) { static_assert(M::Dim == 3); raise::ErrorIf(res.size() != M::Dim, "res.size() != M::Dim", HERE); @@ -92,7 +92,7 @@ void testPusher(const std::vector& res) { Kokkos::parallel_for( "init 3D", range_ext, - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { emfield(i1, i2, i3, em::ex1) = ZERO; emfield(i1, i2, i3, em::ex2) = ZERO; emfield(i1, i2, i3, em::ex3) = ZERO; diff --git a/tests/kernels/particle_moments.cpp b/tests/kernels/particle_moments.cpp index 16c191d35..0f501bf68 100644 --- a/tests/kernels/particle_moments.cpp +++ b/tests/kernels/particle_moments.cpp @@ -34,7 +34,7 @@ void errorIf(bool condition, const std::string& message) { } template -void put_value(array_t& arr, T v, index_t p) { +void put_value(array_t& arr, T v, prtlidx_t p) { auto h = Kokkos::create_mirror_view(arr); Kokkos::deep_copy(h, arr); h(p) = v; @@ -44,7 +44,7 @@ void put_value(array_t& arr, T v, index_t p) { inline static constexpr auto epsilon = std::numeric_limits::epsilon(); template -void testParticleMoments(const std::vector& res, +void testParticleMoments(const std::vector& res, const boundaries_t& ext, const std::map& params = {}, const real_t acc = ONE) { @@ -292,7 +292,7 @@ auto main(int argc, char* argv[]) -> int { 10); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/prtl_bc.cpp b/tests/kernels/prtl_bc.cpp index 037d59035..898eb2d9c 100644 --- a/tests/kernels/prtl_bc.cpp +++ b/tests/kernels/prtl_bc.cpp @@ -38,7 +38,7 @@ auto equal(real_t a, real_t b, const std::string& msg) -> bool { } template -void put_value(array_t& arr, T v, index_t p) { +void put_value(array_t& arr, T v, prtlidx_t p) { auto h = Kokkos::create_mirror_view(arr); Kokkos::deep_copy(h, arr); h(p) = v; @@ -46,7 +46,7 @@ void put_value(array_t& arr, T v, index_t p) { } template -void testPeriodicBC(const std::vector& res, +void testPeriodicBC(const std::vector& res, const boundaries_t& ext, const std::map& params = {}) { errorIf(res.size() != M::Dim, "res.size() != M::Dim"); @@ -143,7 +143,7 @@ void testPeriodicBC(const std::vector& res, { coord_t xCd { ZERO }, xi { ZERO }; - std::size_t prtl_idx; + npart_t prtl_idx; // set up particle #1 prtl_idx = 0; @@ -392,20 +392,20 @@ auto main(int argc, char* argv[]) -> int { try { using namespace ntt; - const std::vector res1d { 50 }; - const boundaries_t ext1d { - { 0.0, 1000.0 }, + const std::vector res1d { 50 }; + const boundaries_t ext1d { + { 0.0, 1000.0 }, }; - const std::vector res2d { 30, 20 }; - const boundaries_t ext2d { - { -15.0, 15.0 }, - { -10.0, 10.0 }, + const std::vector res2d { 30, 20 }; + const boundaries_t ext2d { + { -15.0, 15.0 }, + { -10.0, 10.0 }, }; - const std::vector res3d { 10, 10, 10 }; - const boundaries_t ext3d { - { 0.0, 1.0 }, - { 0.0, 1.0 }, - { 0.0, 1.0 } + const std::vector res3d { 10, 10, 10 }; + const boundaries_t ext3d { + { 0.0, 1.0 }, + { 0.0, 1.0 }, + { 0.0, 1.0 } }; testPeriodicBC>(res1d, ext1d, {}); testPeriodicBC>(res2d, ext2d, {}); diff --git a/tests/kernels/prtls_to_phys.cpp b/tests/kernels/prtls_to_phys.cpp index 8f9d1760a..16b811b34 100644 --- a/tests/kernels/prtls_to_phys.cpp +++ b/tests/kernels/prtls_to_phys.cpp @@ -27,7 +27,7 @@ using namespace ntt; template struct Checker { Checker(const M& metric, - std::size_t stride, + npart_t stride, const array_t& i1, const array_t& dx1, const array_t& i2, @@ -67,8 +67,8 @@ struct Checker { , buff_wei { buff_wei } , buff_pld_i { buff_pld_i } {} - Inline void operator()(index_t p) const { - std::size_t pold = p * stride; + Inline void operator()(prtlidx_t p) const { + prtlidx_t pold = p * stride; real_t x1 = static_cast(i1(pold)) + static_cast(dx1(pold)); real_t x2 = static_cast(i2(pold)) + static_cast(dx2(pold)); real_t x1_phys = metric.template convert<1, Crd::Cd, Crd::Ph>(x1); @@ -106,7 +106,7 @@ struct Checker { private: const M metric; - std::size_t stride; + npart_t stride; const array_t i1; const array_t dx1; const array_t i2; @@ -128,7 +128,7 @@ struct Checker { }; template -void testPrtl2PhysSR(const std::vector& res, +void testPrtl2PhysSR(const std::vector& res, const boundaries_t& ext, const std::map& params = {}) { static constexpr Dimension D = M::Dim; @@ -144,7 +144,7 @@ void testPrtl2PhysSR(const std::vector& res, const M metric { res, extent, params }; - const std::size_t nprtl = 100; + const npart_t nprtl = 100; array_t i1 { "i1", nprtl }; array_t dx1 { "dx1", nprtl }; @@ -161,12 +161,12 @@ void testPrtl2PhysSR(const std::vector& res, array_t i3; array_t dx3; - const std::size_t stride = 2; + const npart_t stride = 2; array_t out_indices { "out_indices", nprtl / stride }; Kokkos::parallel_for( "Init", nprtl, - Lambda(index_t p) { + Lambda(prtlidx_t p) { // init "random" values i1(p) = p % 10; i2(p) = (p + nprtl) % 10; @@ -268,7 +268,7 @@ auto main(int argc, char* argv[]) -> int { { { "r0", 0.0 }, { "h", 0.25 } }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/kernels/pusher.cpp b/tests/kernels/pusher.cpp index ad571555d..c429c129f 100644 --- a/tests/kernels/pusher.cpp +++ b/tests/kernels/pusher.cpp @@ -44,7 +44,7 @@ void check_value(unsigned int t, } template -void put_value(array_t& arr, T v, index_t p) { +void put_value(array_t& arr, T v, prtlidx_t p) { auto h = Kokkos::create_mirror_view(arr); Kokkos::deep_copy(h, arr); h(p) = v; @@ -52,7 +52,7 @@ void put_value(array_t& arr, T v, index_t p) { } template -void testPusher(const std::vector& res) { +void testPusher(const std::vector& res) { static_assert(M::Dim == 3); raise::ErrorIf(res.size() != M::Dim, "res.size() != M::Dim", HERE); @@ -86,7 +86,7 @@ void testPusher(const std::vector& res) { Kokkos::parallel_for( "init 3D", range_ext, - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { emfield(i1, i2, i3, em::ex1) = ZERO; emfield(i1, i2, i3, em::ex2) = ZERO; emfield(i1, i2, i3, em::ex3) = ZERO; diff --git a/tests/kernels/reduced_stats.cpp b/tests/kernels/reduced_stats.cpp index c62831bf6..79aa03637 100644 --- a/tests/kernels/reduced_stats.cpp +++ b/tests/kernels/reduced_stats.cpp @@ -28,15 +28,15 @@ class Fill_kernel { raise::ErrorIf(c_ >= N, "c > N", HERE); } - Inline void operator()(index_t i1) const { + Inline void operator()(cellidx_t i1) const { arr(i1, c) = v; } - Inline void operator()(index_t i1, index_t i2) const { + Inline void operator()(cellidx_t i1, cellidx_t i2) const { arr(i1, i2, c) = v; } - Inline void operator()(index_t i1, index_t i2, index_t i3) const { + Inline void operator()(cellidx_t i1, cellidx_t i2, cellidx_t i3) const { arr(i1, i2, i3, c) = v; } }; @@ -81,9 +81,9 @@ auto almost_equal(real_t a, real_t b, real_t acc) -> bool { } template -void testReducedStats(const std::vector& res, - const boundaries_t& ext, - const real_t acc) { +void testReducedStats(const std::vector& res, + const boundaries_t& ext, + const real_t acc) { raise::ErrorIf(res.size() != M::Dim, "Invalid resolution size", HERE); M metric { res, ext, {} }; diff --git a/tests/metrics/coord_trans.cpp b/tests/metrics/coord_trans.cpp index f2bd7e464..5149e8020 100644 --- a/tests/metrics/coord_trans.cpp +++ b/tests/metrics/coord_trans.cpp @@ -41,9 +41,9 @@ Inline auto equal(const coord_t& a, } template -Inline void unravel(std::size_t idx, - tuple_t& ijk, - const tuple_t& res) { +Inline void unravel(ncells_t idx, + tuple_t& ijk, + const tuple_t& res) { for (auto d { 0u }; d < D; ++d) { ijk[d] = idx % res[d]; idx /= res[d]; @@ -51,7 +51,7 @@ Inline void unravel(std::size_t idx, } template -void testMetric(const std::vector& res, +void testMetric(const std::vector& res, const boundaries_t& ext, const real_t acc = ONE, const std::map& params = {}) { @@ -63,8 +63,8 @@ void testMetric(const std::vector& res, M metric(res, ext, params); - tuple_t res_tup; - std::size_t npts = 1; + tuple_t res_tup; + ncells_t npts = 1; for (auto d = 0; d < M::Dim; ++d) { res_tup[d] = res[d]; npts *= res[d]; @@ -75,8 +75,8 @@ void testMetric(const std::vector& res, Kokkos::parallel_reduce( "code-sph-phys", npts, - Lambda(index_t n, unsigned long& wrongs) { - tuple_t idx; + Lambda(cellidx_t n, unsigned long& wrongs) { + tuple_t idx; unravel(n, idx, res_tup); coord_t x_Code_1 { ZERO }; coord_t x_Code_2 { ZERO }; @@ -124,8 +124,8 @@ auto main(int argc, char* argv[]) -> int { try { using namespace ntt; using namespace metric; - const auto res2d = std::vector { 64, 32 }; - const auto res3d = std::vector { 64, 32, 16 }; + const auto res2d = std::vector { 64, 32 }; + const auto res3d = std::vector { 64, 32, 16 }; const auto ext1dcart = boundaries_t { { 10.0, 20.0 } }; @@ -147,13 +147,13 @@ auto main(int argc, char* argv[]) -> int { { "h", (real_t)0.25 } }; - testMetric>({ 128 }, ext1dcart); + testMetric>({ 128u }, ext1dcart); testMetric>(res2d, ext2dcart, 200); testMetric>(res3d, ext3dcart, 500); testMetric>(res2d, extsph, 10); testMetric>(res2d, extsph, 100, params); - const auto resks = std::vector { 64, 54 }; + const auto resks = std::vector { 64, 54 }; const auto extsks = boundaries_t { { 0.8, 50.0 }, { 0.0, constant::PI } @@ -163,7 +163,7 @@ auto main(int argc, char* argv[]) -> int { }; testMetric>(resks, extsks, 150, paramsks); - const auto resqks = std::vector { 64, 42 }; + const auto resqks = std::vector { 64, 42 }; const auto extqks = boundaries_t { { 0.8, 10.0 }, { 0.0, constant::PI } @@ -175,7 +175,7 @@ auto main(int argc, char* argv[]) -> int { }; testMetric>(resqks, extqks, 500, paramsqks); - const auto resks0 = std::vector { 64, 54 }; + const auto resks0 = std::vector { 64, 54 }; const auto extks0 = boundaries_t { { 0.5, 20.0 }, { 0.0, constant::PI } @@ -183,7 +183,7 @@ auto main(int argc, char* argv[]) -> int { testMetric>(resks0, extks0, 150); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/metrics/ks-qks.cpp b/tests/metrics/ks-qks.cpp index ea05c0f92..47c6524f5 100644 --- a/tests/metrics/ks-qks.cpp +++ b/tests/metrics/ks-qks.cpp @@ -35,9 +35,9 @@ Inline auto equal(const vec_t& a, } template -Inline void unravel(std::size_t idx, - tuple_t& ijk, - const tuple_t& res) { +Inline void unravel(ncells_t idx, + tuple_t& ijk, + const tuple_t& res) { for (auto d { 0u }; d < D; ++d) { ijk[d] = idx % res[d]; idx /= res[d]; @@ -45,7 +45,7 @@ Inline void unravel(std::size_t idx, } template -void testMetric(const std::vector& res, +void testMetric(const std::vector& res, const boundaries_t& ext, const real_t acc = ONE, const std::map& params = {}) { @@ -56,9 +56,9 @@ void testMetric(const std::vector& res, errorIf(e.first >= e.second, "e.first >= e.second"); } - M metric(res, ext, params); - tuple_t res_tup; - std::size_t npts = 1; + M metric(res, ext, params); + tuple_t res_tup; + ncells_t npts = 1; for (auto d = 0; d < M::Dim; ++d) { res_tup[d] = res[d]; npts *= res[d]; @@ -69,8 +69,8 @@ void testMetric(const std::vector& res, Kokkos::parallel_for( "h_ij/hij", npts, - Lambda(index_t n) { - tuple_t idx; + Lambda(cellidx_t n) { + tuple_t idx; unravel(n, idx, res_tup); coord_t x_Code { ZERO }; coord_t x_Phys { ZERO }; @@ -193,7 +193,7 @@ auto main(int argc, char* argv[]) -> int { { { "r0", -TWO }, { "h", ZERO }, { "a", (real_t)0.8 } }); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/metrics/minkowski.cpp b/tests/metrics/minkowski.cpp index d225919cd..c35631080 100644 --- a/tests/metrics/minkowski.cpp +++ b/tests/metrics/minkowski.cpp @@ -67,7 +67,7 @@ auto main(int argc, char* argv[]) -> int { "code-phys", CreateRangePolicy({ N_GHOSTS, N_GHOSTS, N_GHOSTS }, { nx + N_GHOSTS, ny + N_GHOSTS, nz + N_GHOSTS }), - Lambda(index_t i1, index_t i2, index_t i3, unsigned long& wrongs) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3, unsigned long& wrongs) { const coord_t x_Code { COORD(i1), COORD(i2), COORD(i3) }; coord_t x_Sph { ZERO, ZERO, ZERO }; coord_t x_Phys { ZERO, ZERO, ZERO }; @@ -89,7 +89,7 @@ auto main(int argc, char* argv[]) -> int { all_wrongs); errorIf(all_wrongs != 0u, "code-phys-sph transformations failed"); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; ntt::GlobalFinalize(); return 1; } diff --git a/tests/metrics/sph-qsph.cpp b/tests/metrics/sph-qsph.cpp index faac28562..109f42196 100644 --- a/tests/metrics/sph-qsph.cpp +++ b/tests/metrics/sph-qsph.cpp @@ -35,9 +35,9 @@ Inline auto equal(const vec_t& a, } template -Inline void unravel(std::size_t idx, - tuple_t& ijk, - const tuple_t& res) { +Inline void unravel(ncells_t idx, + tuple_t& ijk, + const tuple_t& res) { for (auto d { 0u }; d < D; ++d) { ijk[d] = idx % res[d]; idx /= res[d]; @@ -45,7 +45,7 @@ Inline void unravel(std::size_t idx, } template -void testMetric(const std::vector& res, +void testMetric(const std::vector& res, const boundaries_t& ext, const real_t acc = ONE, const std::map& params = {}) { @@ -56,9 +56,9 @@ void testMetric(const std::vector& res, errorIf(e.first >= e.second, "e.first >= e.second"); } - M metric(res, ext, params); - tuple_t res_tup; - std::size_t npts = 1; + M metric(res, ext, params); + tuple_t res_tup; + ncells_t npts = 1; for (auto d = 0; d < M::Dim; ++d) { res_tup[d] = res[d]; npts *= res[d]; @@ -68,8 +68,8 @@ void testMetric(const std::vector& res, Kokkos::parallel_reduce( "h_ij", npts, - Lambda(index_t n, unsigned long& wrongs) { - tuple_t idx; + Lambda(cellidx_t n, unsigned long& wrongs) { + tuple_t idx; unravel(n, idx, res_tup); coord_t x_Code { ZERO }; coord_t x_Phys { ZERO }; @@ -113,7 +113,7 @@ auto main(int argc, char* argv[]) -> int { try { using namespace ntt; using namespace metric; - const auto res = std::vector { 64, 32 }; + const auto res = std::vector { 64, 32 }; const auto ext = boundaries_t { { 1.0, 10.0 }, { 0.0, constant::PI } @@ -127,7 +127,7 @@ auto main(int argc, char* argv[]) -> int { testMetric>(res, ext, 10, params); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/metrics/sr-cart-sph.cpp b/tests/metrics/sr-cart-sph.cpp index 6ca6a52d7..4f1a7e52b 100644 --- a/tests/metrics/sr-cart-sph.cpp +++ b/tests/metrics/sr-cart-sph.cpp @@ -38,9 +38,9 @@ Inline auto equal(const coord_t& a, } template -Inline void unravel(std::size_t idx, - tuple_t& ijk, - const tuple_t& res) { +Inline void unravel(ncells_t idx, + tuple_t& ijk, + const tuple_t& res) { for (auto d { 0u }; d < D; ++d) { ijk[d] = idx % res[d]; idx /= res[d]; @@ -48,7 +48,7 @@ Inline void unravel(std::size_t idx, } template -void testMetric(const std::vector& res, +void testMetric(const std::vector& res, const boundaries_t& ext, const real_t acc = ONE, const std::map& params = {}) { @@ -60,8 +60,8 @@ void testMetric(const std::vector& res, M metric(res, ext, params); - tuple_t res_tup; - std::size_t npts = 1; + tuple_t res_tup; + ncells_t npts = 1; for (auto d = 0; d < M::Dim; ++d) { res_tup[d] = res[d]; npts *= res[d]; @@ -72,8 +72,8 @@ void testMetric(const std::vector& res, Kokkos::parallel_reduce( "code-cart-sph", npts, - Lambda(index_t n, unsigned long& wrongs) { - tuple_t idx; + Lambda(cellidx_t n, unsigned long& wrongs) { + tuple_t idx; unravel(n, idx, res_tup); // cartesian has to have full 3D coordinates in spherical coords @@ -120,8 +120,8 @@ auto main(int argc, char* argv[]) -> int { try { using namespace ntt; using namespace metric; - const auto res2d = std::vector { 64, 32 }; - const auto res3d = std::vector { 64, 32, 16 }; + const auto res2d = std::vector { 64, 32 }; + const auto res3d = std::vector { 64, 32, 16 }; const auto ext1dcart = boundaries_t { { 10.0, 20.0 } }; @@ -150,7 +150,7 @@ auto main(int argc, char* argv[]) -> int { testMetric>(res2d, extsph, 200, params); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/metrics/vec_trans.cpp b/tests/metrics/vec_trans.cpp index e9a03aa50..5715c58a7 100644 --- a/tests/metrics/vec_trans.cpp +++ b/tests/metrics/vec_trans.cpp @@ -41,9 +41,9 @@ Inline auto equal(const vec_t& a, } template -Inline void unravel(std::size_t idx, - tuple_t& ijk, - const tuple_t& res) { +Inline void unravel(ncells_t idx, + tuple_t& ijk, + const tuple_t& res) { for (auto d { 0u }; d < D; ++d) { ijk[d] = idx % res[d]; idx /= res[d]; @@ -51,7 +51,7 @@ Inline void unravel(std::size_t idx, } template -void testMetric(const std::vector& res, +void testMetric(const std::vector& res, const boundaries_t& ext, const real_t acc = ONE, const std::map& params = {}) { @@ -63,8 +63,8 @@ void testMetric(const std::vector& res, M metric(res, ext, params); - tuple_t res_tup; - std::size_t npts = 1; + tuple_t res_tup; + ncells_t npts = 1; for (auto d = 0; d < M::Dim; ++d) { res_tup[d] = res[d]; npts *= res[d]; @@ -75,8 +75,8 @@ void testMetric(const std::vector& res, Kokkos::parallel_reduce( "hat-cntrv-cov", npts, - Lambda(index_t n, unsigned long& wrongs) { - tuple_t idx; + Lambda(cellidx_t n, unsigned long& wrongs) { + tuple_t idx; unravel(n, idx, res_tup); coord_t x_Code { ZERO }; for (auto d { 0u }; d < M::Dim; ++d) { @@ -176,8 +176,8 @@ auto main(int argc, char* argv[]) -> int { using namespace ntt; using namespace metric; - const auto res2d = std::vector { 64, 32 }; - const auto res3d = std::vector { 64, 32, 16 }; + const auto res2d = std::vector { 64, 32 }; + const auto res3d = std::vector { 64, 32, 16 }; const auto ext1dcart = boundaries_t { { 10.0, 20.0 } }; @@ -205,7 +205,7 @@ auto main(int argc, char* argv[]) -> int { // testMetric>(res2d, extsph, 10); // testMetric>(res2d, extsph, 10, params); - // const auto resks = std::vector { 64, 54 }; + // const auto resks = std::vector { 64, 54 }; // const auto extsgr = boundaries_t { // {0.8, 50.0}, // {0.0, constant::PI} @@ -217,7 +217,7 @@ auto main(int argc, char* argv[]) -> int { // }; // testMetric>(resks, extsgr, 150, paramsks); // - const auto resqks = std::vector { 64, 42 }; + const auto resqks = std::vector { 64, 42 }; const auto extqks = boundaries_t { { 0.8, 10.0 }, { 0.0, constant::PI } @@ -229,7 +229,7 @@ auto main(int argc, char* argv[]) -> int { }; testMetric>(resqks, extqks, 500, paramsqks); // - // const auto resks0 = std::vector { 64, 54 }; + // const auto resks0 = std::vector { 64, 54 }; // const auto extks0 = boundaries_t { // {0.5, 20.0}, // {0.0, constant::PI} @@ -237,7 +237,7 @@ auto main(int argc, char* argv[]) -> int { // testMetric>(resks0, extks0, 10); } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; Kokkos::finalize(); return 1; } diff --git a/tests/output/fields.cpp b/tests/output/fields.cpp index de86af2f4..fd7b89438 100644 --- a/tests/output/fields.cpp +++ b/tests/output/fields.cpp @@ -106,7 +106,7 @@ auto main() -> int { raise::ErrorIf(t.comp.size() != 6, "T should have 6 component", HERE); } } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } return 0; diff --git a/tests/output/stats.cpp b/tests/output/stats.cpp index 11e9961e3..c021ce2cf 100644 --- a/tests/output/stats.cpp +++ b/tests/output/stats.cpp @@ -107,7 +107,7 @@ auto main() -> int { raise::ErrorIf(custom.is_vector(), "Custom should not be a vector", HERE); } } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; return 1; } return 0; diff --git a/tests/output/writer-mpi.cpp b/tests/output/writer-mpi.cpp index 45a2f9ab2..7c5bff7a7 100644 --- a/tests/output/writer-mpi.cpp +++ b/tests/output/writer-mpi.cpp @@ -47,7 +47,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "fill", CreateRangePolicy({ i1min }, { i1max }), - Lambda(index_t i1) { + Lambda(cellidx_t i1) { const auto i1_ = static_cast(i1); field(i1, 0) = i1_; field(i1, 1) = -i1_; @@ -99,7 +99,7 @@ auto main(int argc, char* argv[]) -> int { fs::path(fmt::format("fields.%08u.bp", time)), adios2::Mode::Read); for (auto st = 0u; reader.BeginStep() == adios2::StepStatus::OK; ++st) { - raise::ErrorIf(io.InquireAttribute("NGhosts").Data()[0] != 0, + raise::ErrorIf(io.InquireAttribute("NGhosts").Data()[0] != 0, "NGhosts is not correct", HERE); raise::ErrorIf( @@ -160,7 +160,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "check", CreateRangePolicy({ 0 }, { l_size_dwn }), - Lambda(index_t i1) { + Lambda(cellidx_t i1) { if (not cmp::AlmostEqual( field_read(i1), field(i1 * dwn1 + first_cell + i1min, cntr))) { @@ -186,7 +186,7 @@ auto main(int argc, char* argv[]) -> int { } } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; CallOnce([]() { cleanup(); }); diff --git a/tests/output/writer-nompi.cpp b/tests/output/writer-nompi.cpp index 5741515a1..c108d0e1c 100644 --- a/tests/output/writer-nompi.cpp +++ b/tests/output/writer-nompi.cpp @@ -56,7 +56,7 @@ auto main(int argc, char* argv[]) -> int { "fill", CreateRangePolicy({ i1min, i2min, i3min }, { i1max, i2max, i3max }), - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { const auto i1_ = static_cast(i1); const auto i2_ = static_cast(i2); const auto i3_ = static_cast(i3); @@ -112,7 +112,7 @@ auto main(int argc, char* argv[]) -> int { const auto layoutRight = io.InquireAttribute("LayoutRight").Data()[0] == 1; - raise::ErrorIf(io.InquireAttribute("NGhosts").Data()[0] != 0, + raise::ErrorIf(io.InquireAttribute("NGhosts").Data()[0] != 0, "NGhosts is not correct", HERE); raise::ErrorIf( @@ -181,7 +181,7 @@ auto main(int argc, char* argv[]) -> int { Kokkos::parallel_for( "check", CreateRangePolicy({ 0, 0, 0 }, { nx1_r, nx2_r, nx3_r }), - Lambda(index_t i1, index_t i2, index_t i3) { + Lambda(cellidx_t i1, cellidx_t i2, cellidx_t i3) { if (not cmp::AlmostEqual(field_read(i1, i2, i3), field(i1 * dwn1 + i1min, i2 * dwn2 + i2min, @@ -216,7 +216,7 @@ auto main(int argc, char* argv[]) -> int { } } } catch (std::exception& e) { - std::cerr << e.what() << std::endl; + std::cerr << e.what() << '\n'; cleanup(); Kokkos::finalize(); return 1; From 6ecfef11f714827019206138ad46bc620f7c6ab8 Mon Sep 17 00:00:00 2001 From: haykh Date: Mon, 4 May 2026 17:45:51 -0400 Subject: [PATCH 11/12] rm 2body --- src/archetypes/twobody_interactions.h | 192 -------------------------- 1 file changed, 192 deletions(-) delete mode 100644 src/archetypes/twobody_interactions.h diff --git a/src/archetypes/twobody_interactions.h b/src/archetypes/twobody_interactions.h deleted file mode 100644 index 8e26e7cbe..000000000 --- a/src/archetypes/twobody_interactions.h +++ /dev/null @@ -1,192 +0,0 @@ -// #ifndef ARCHETYPES_TWO_BODY_INTERACTIONS_H -// #define ARCHETYPES_TWO_BODY_INTERACTIONS_H -// -// #include "traits/metric.h" -// -// #include "framework/containers/particles.h" -// -// #include -// #include -// -// #include -// #include -// #include -// -// #include "utils.h" -// -// namespace arch { -// -// struct CollisionSpecies { -// const spidx_t sp; -// const npart_t npart; -// const ncells_t num_tiles; -// -// const array_t tileidx; -// const array_t num_ppt; -// -// CollisionSpecies(spidx_t sp, -// npart_t npart, -// const array_t& tileidx, -// const array_t& num_ppt) -// : sp { sp } -// , npart { npart } -// , num_tiles { static_cast(num_ppt.extent(0)) } -// , tileidx { tileidx } -// , num_ppt { num_ppt } {} -// }; -// -// struct CollisionGroup { -// std::vector group; -// -// array_t combined_idx; -// array_t combined_tileidx; -// array_t combined_num_ppt; -// array_t tile_offsets; -// -// ncells_t num_tiles { 0u }; -// -// [[nodiscard]] -// auto total_npart() -> npart_t { -// npart_t total_npart = 0u; -// for (const auto& species : group) { -// total_npart += species.npart; -// } -// return total_npart; -// } -// -// CollisionGroup(const std::vector& particles, -// const Domain& domain, -// ncells_t tile_size, -// random_pool_t& random_pool) { -// for (const auto& species : particles) { -// auto tile_indexing = PositionToTileIndex(species.i1, -// species.i2, -// species.get_npart(), -// domain.nx1, -// domain.nx2, -// tile_size); -// Kokkos::parallel_for("TileIndexing", species.get_npart(), tile_indexing); -// group.emplace_back(species.sp, -// species.get_npart(), -// tile_indexing.tile_indices, -// tile_indexing.num_ppt); -// if (num_tiles == 0u) { -// num_tiles = group.back().num_tiles; -// } else if (num_tiles != group.back().num_tiles) { -// throw std::runtime_error { "unequal num_tiles" }; -// } -// if (group.back().tileidx.extent(0) != species.get_npart()) { -// throw std::runtime_error { "tileidx must have the same extent as " -// "npart for all species in group" }; -// } -// } -// -// const auto tot_npart = total_npart(); -// combined_idx = array_t { "combined_idx", tot_npart }; -// combined_tileidx = array_t { "combined_tileidx", tot_npart }; -// combined_num_ppt = array_t { "combined_num_ppt", num_tiles }; -// tile_offsets = array_t { "tile_offsets", num_tiles }; -// -// { -// // combine particle indices in the group & compute total number in each tile -// npart_t offset = 0u; -// for (const auto& species : group) { -// Kokkos::parallel_for( -// "CombineInGroup", -// species.npart, -// ClassLambda(const npart_t p) { -// // pack species idx into top 8 bits + prtl index into the remaining 56 bits -// combined_idx(offset + p) = (static_cast(species.sp) << 56) | -// static_cast(p); -// combined_tileidx(offset + p) = species.tileidx(p); -// }); -// offset += species.npart; -// Kokkos::parallel_for( -// "CombineNumPpt", -// species.num_tiles, -// ClassLambda(const ncells_t t) { -// combined_num_ppt(t) += species.num_ppt(t); -// }); -// Kokkos::fence(); -// } -// } -// { -// // randomly shuffle particles within each tile and sort by tiles -// array_t shuffle_key { "shuffle_key", tot_npart }; -// Kokkos::parallel_for( -// "PackRandom", -// tot_npart, -// ClassLambda(const npart_t p) { -// auto gen = random_pool.get_state(); -// const auto rnd = static_cast(gen.urand()); -// random_pool.free_state(gen); -// const auto tile_idx = static_cast(combined_tileidx(p)); -// // packing top 32 bits with tile index, and the rest -- random -// shuffle_key(p) = (tile_idx << 32) | rnd; -// }); -// Kokkos::Experimental::sort_by_key(Kokkos::DefaultExecutionSpace {}, -// shuffle_key, -// combined_idx); -// } -// { -// // compute index offsets for each tile -// Kokkos::parallel_scan( -// "TileOffsets", -// num_tiles, -// ClassLambda(const ncells_t t, npart_t& acc, const bool final) { -// if (final) { -// tile_offsets(t) = acc; -// } -// acc += combined_num_ppt(t); -// }); -// } -// } -// }; -// -// template -// void TwoBodyInteraction(const std::vector& species1, -// const std::vector& species2, -// const Domain& domain, -// ncells_t tile_size, -// random_pool_t& random_pool, -// const C& collision_policy) { -// const auto group1 = CollisionGroup(species1, domain, tile_size, random_pool); -// const auto group2 = CollisionGroup(species2, domain, tile_size, random_pool); -// if (group1.num_tiles != group2.num_tiles) { -// throw std::runtime_error("number of tiles differ in group1 vs group2"); -// } -// const auto num_tiles = group1.num_tiles; -// -// const auto& combined_idx1 = group1.combined_idx; -// const auto& combined_idx2 = group2.combined_idx; -// const auto& combined_num_ppt1 = group1.combined_num_ppt; -// const auto& combined_num_ppt2 = group2.combined_num_ppt; -// const auto& tile_offsets1 = group1.tile_offsets; -// const auto& tile_offsets2 = group2.tile_offsets; -// -// Kokkos::parallel_for( -// "EmitPairs", -// Kokkos::TeamPolicy<>(num_tiles, Kokkos::AUTO), -// Lambda(const Kokkos::TeamPolicy<>::member_type& team) { -// const auto t = team.league_rank(); -// const auto k = Kokkos::min(combined_num_ppt1(t), combined_num_ppt2(t)); -// const auto o1 = tile_offsets1(t); -// const auto o2 = tile_offsets2(t); -// Kokkos::parallel_for(Kokkos::TeamThreadRange(team, k), [&](const npart_t i) { -// // unpack the higher 8 bits -// const auto sp1 = static_cast(combined_idx1(o1 + i) >> 56); -// const auto sp2 = static_cast(combined_idx2(o2 + i) >> 56); -// -// // unpack the lower 56 bits -// const auto p1 = static_cast(combined_idx1(o1 + i) & -// ((1ull << 56) - 1)); -// const auto p2 = static_cast(combined_idx2(o2 + i) & -// ((1ull << 56) - 1)); -// collision_policy(sp1, p1, sp2, p2); -// }); -// }); -// } -// -// } // namespace arch -// -// #endif From 8cdad8ae4c85bcafeb549220272b97dac0e7c038 Mon Sep 17 00:00:00 2001 From: haykh Date: Mon, 4 May 2026 17:47:11 -0400 Subject: [PATCH 12/12] npart_t 64->32 bit --- src/global/global.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/global/global.h b/src/global/global.h index 08fbbf8b0..a509e7c30 100644 --- a/src/global/global.h +++ b/src/global/global.h @@ -381,7 +381,7 @@ using duration_t = double; using simtime_t = double; using timestep_t = uint32_t; using ncells_t = uint32_t; -using npart_t = uint64_t; +using npart_t = uint32_t; // walltime using timestamp_t = std::chrono::time_point;