|
1 | 1 | //========================================================================================
|
2 |
| -// (C) (or copyright) 2020-2023. Triad National Security, LLC. All rights reserved. |
| 2 | +// (C) (or copyright) 2020-2024. Triad National Security, LLC. All rights reserved. |
3 | 3 | //
|
4 | 4 | // This program was produced under U.S. Government contract 89233218CNA000001 for Los
|
5 | 5 | // Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC
|
@@ -77,13 +77,80 @@ struct v5 : public parthenon::variable_names::base_t<false> {
|
77 | 77 | static std::string name() { return "v5"; }
|
78 | 78 | };
|
79 | 79 |
|
| 80 | +using parthenon::variable_names::ANYDIM; |
| 81 | +struct v7 : public parthenon::variable_names::base_t<false, ANYDIM, 3> { |
| 82 | + template <class... Ts> |
| 83 | + KOKKOS_INLINE_FUNCTION v7(Ts &&...args) |
| 84 | + : parthenon::variable_names::base_t<false, ANYDIM, 3>(std::forward<Ts>(args)...) {} |
| 85 | + static std::string name() { return "v7"; } |
| 86 | +}; |
| 87 | + |
80 | 88 | } // namespace
|
81 | 89 |
|
82 | 90 | TEST_CASE("Test behavior of sparse packs", "[SparsePack]") {
|
| 91 | + constexpr int N = 6; |
| 92 | + constexpr int NDIM = 3; |
| 93 | + constexpr int NBLOCKS = 9; |
| 94 | + |
| 95 | + GIVEN("A tensor variable on a mesh") { |
| 96 | + const std::vector<int> tensor_shape{N, N, N, 3, 3}; |
| 97 | + Metadata m_tensor({Metadata::Independent}, tensor_shape); |
| 98 | + auto pkg = std::make_shared<StateDescriptor>("Test package"); |
| 99 | + pkg->AddField<v7>(m_tensor); |
| 100 | + BlockList_t block_list = MakeBlockList(pkg, NBLOCKS, N, NDIM); |
| 101 | + |
| 102 | + MeshData<Real> mesh_data("base"); |
| 103 | + mesh_data.Set(block_list, nullptr); |
| 104 | + |
| 105 | + WHEN("We initialize the independent variables by hand and deallocate one") { |
| 106 | + auto ib = block_list[0]->cellbounds.GetBoundsI(IndexDomain::entire); |
| 107 | + auto jb = block_list[0]->cellbounds.GetBoundsJ(IndexDomain::entire); |
| 108 | + auto kb = block_list[0]->cellbounds.GetBoundsK(IndexDomain::entire); |
| 109 | + for (int b = 0; b < NBLOCKS; ++b) { |
| 110 | + auto &pmb = block_list[b]; |
| 111 | + auto &pmbd = pmb->meshblock_data.Get(); |
| 112 | + auto var = pmbd->Get("v7"); |
| 113 | + auto var5 = var.data.Get<5>(); |
| 114 | + int slower_rank = var5.GetDim(5); |
| 115 | + int faster_rank = var5.GetDim(4); |
| 116 | + par_for( |
| 117 | + loop_pattern_mdrange_tag, "initializev7", DevExecSpace(), kb.s, kb.e, jb.s, |
| 118 | + jb.e, ib.s, ib.e, KOKKOS_LAMBDA(int k, int j, int i) { |
| 119 | + for (int l = 0; l < slower_rank; ++l) { |
| 120 | + for (int m = 0; m < faster_rank; ++m) { |
| 121 | + Real n = m + 1e1 * l; |
| 122 | + var5(l, m, k, j, i) = n; |
| 123 | + } |
| 124 | + } |
| 125 | + }); |
| 126 | + } |
| 127 | + THEN("A sparse pack can correctly index into tensor types") { |
| 128 | + auto desc = parthenon::MakePackDescriptor<v7>(pkg.get()); |
| 129 | + auto sparse_pack = desc.GetPack(&mesh_data); |
| 130 | + int nwrong = 0; |
| 131 | + int nl = tensor_shape[4]; |
| 132 | + int nm = tensor_shape[3]; |
| 133 | + par_reduce( |
| 134 | + loop_pattern_mdrange_tag, "check vector", DevExecSpace(), 0, |
| 135 | + sparse_pack.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e, ib.s, ib.e, |
| 136 | + KOKKOS_LAMBDA(int b, int k, int j, int i, int <ot) { |
| 137 | + // 0-th is ANYDIM, 1st is 3. |
| 138 | + for (int l = 0; l < nl; ++l) { |
| 139 | + for (int m = 0; m < nm; ++m) { |
| 140 | + Real n = m + 1e1 * l; |
| 141 | + if (sparse_pack(b, v7(l, m), k, j, i) != n) { |
| 142 | + ltot += 1; |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + }, |
| 147 | + nwrong); |
| 148 | + REQUIRE(nwrong == 0); |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + |
83 | 153 | GIVEN("A set of meshblocks and meshblock and mesh data") {
|
84 |
| - constexpr int N = 6; |
85 |
| - constexpr int NDIM = 3; |
86 |
| - constexpr int NBLOCKS = 9; |
87 | 154 | const std::vector<int> scalar_shape{N, N, N};
|
88 | 155 | const std::vector<int> vector_shape{N, N, N, 3};
|
89 | 156 |
|
@@ -122,6 +189,7 @@ TEST_CASE("Test behavior of sparse packs", "[SparsePack]") {
|
122 | 189 | });
|
123 | 190 | }
|
124 | 191 | }
|
| 192 | + |
125 | 193 | // Deallocate a variable on an arbitrary block
|
126 | 194 | block_list[2]->DeallocateSparse("v3");
|
127 | 195 |
|
|
0 commit comments