diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d30b03bf5d2..de9aa1e8a092 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - [[PR 487]](https://github.com/lanl/parthenon/pull/487) Add default tiling matching `i` index range to MDRange loop pattern. ### Infrastructure (changes irrelevant to downstream codes) +- [[PR 502]](https://github.com/lanl/parthenon/pull/502) Use subviews of a single view for fluxes - [[PR 505]](https://github.com/lanl/parthenon/pull/505) Can also use buffer-pack-in-one function also in `Mesh::Initialize` (and thus during load balancing/mesh refinement). Breaks sparse variables with FillGhost. Enable with `PARTHENON_ENABLE_INIT_PACKING=ON` (default OFF). - [[PR 493]](https://github.com/lanl/parthenon/pull/493) Use subviews of a single view for comm buffers - [[PR 500]](https://github.com/lanl/parthenon/pull/500) Update docker file and CI environment (for Cuda 11.3 and latest `nsys`) diff --git a/src/bvals/bvals_interfaces.hpp b/src/bvals/bvals_interfaces.hpp index 96915780dfde..8c971af5c0f1 100644 --- a/src/bvals/bvals_interfaces.hpp +++ b/src/bvals/bvals_interfaces.hpp @@ -3,7 +3,7 @@ // Copyright(C) 2014 James M. Stone and other code contributors // Licensed under the 3-clause BSD License, see LICENSE file for details //======================================================================================== -// (C) (or copyright) 2020. Triad National Security, LLC. All rights reserved. +// (C) (or copyright) 2020-2021. Triad National Security, LLC. All rights reserved. // // This program was produced under U.S. Government contract 89233218CNA000001 for Los // Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC diff --git a/src/bvals/bvals_var.cpp b/src/bvals/bvals_var.cpp index 84d65a7bdc2e..c6fe68706500 100644 --- a/src/bvals/bvals_var.cpp +++ b/src/bvals/bvals_var.cpp @@ -3,7 +3,7 @@ // Copyright(C) 2014 James M. Stone and other code contributors // Licensed under the 3-clause BSD License, see LICENSE file for details //======================================================================================== -// (C) (or copyright) 2020. Triad National Security, LLC. All rights reserved. +// (C) (or copyright) 2020-2021. Triad National Security, LLC. All rights reserved. // // This program was produced under U.S. Government contract 89233218CNA000001 for Los // Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC diff --git a/src/interface/variable.cpp b/src/interface/variable.cpp index b7594f1750d4..9e7a26e5c6ab 100644 --- a/src/interface/variable.cpp +++ b/src/interface/variable.cpp @@ -1,5 +1,5 @@ //======================================================================================== -// (C) (or copyright) 2020. Triad National Security, LLC. All rights reserved. +// (C) (or copyright) 2020-2021. Triad National Security, LLC. All rights reserved. // // This program was produced under U.S. Government contract 89233218CNA000001 for Los // Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC @@ -14,6 +14,7 @@ #include "interface/variable.hpp" #include +#include #include "bvals/cc/bvals_cc.hpp" #include "mesh/mesh.hpp" @@ -69,13 +70,13 @@ CellVariable::AllocateCopy(const bool allocComms, std::weak_ptr wp // Note that vbvar->var_cc will be set when stage is selected cv->vbvar = vbvar; - // fluxes, etc are always a copy + // fluxes, coarse buffers, etc., are always a copy + // Rely on reference counting and shallow copy of kokkos views + cv->flux_data_ = flux_data_; // reference counted for (int i = 1; i <= 3; i++) { - cv->flux[i] = flux[i]; + cv->flux[i] = flux[i]; // these are subviews } - - // These members are pointers, // point at same memory as src - cv->coarse_s = coarse_s; + cv->coarse_s = coarse_s; // reference counted } } return cv; @@ -85,28 +86,36 @@ CellVariable::AllocateCopy(const bool allocComms, std::weak_ptr wp /// Initialize a 6D variable template void CellVariable::allocateComms(std::weak_ptr wpmb) { - // set up fluxes std::string base_name = label(); + + // TODO(JMM): Note that this approach assumes LayoutRight. Otherwise + // the stride will mess up the types. + if (IsSet(Metadata::Independent)) { - flux[X1DIR] = ParArrayND(base_name + ".fluxX1", GetDim(6), GetDim(5), GetDim(4), - GetDim(3), GetDim(2), GetDim(1)); - if (GetDim(2) > 1) - flux[X2DIR] = ParArrayND(base_name + ".fluxX2", GetDim(6), GetDim(5), GetDim(4), - GetDim(3), GetDim(2), GetDim(1)); - if (GetDim(3) > 1) - flux[X3DIR] = ParArrayND(base_name + ".fluxX3", GetDim(6), GetDim(5), GetDim(4), - GetDim(3), GetDim(2), GetDim(1)); + // Compute size of unified flux_data object and create it. A unified + // flux_data_ object reduces the number of memory allocations per + // variable per meshblock from 5 to 3. + int n_outer = 1 + (GetDim(2) > 1) * (1 + (GetDim(3) > 1)); + // allocate fluxes + flux_data_ = ParArray7D(base_name + ".flux_data", n_outer, GetDim(6), GetDim(5), + GetDim(4), GetDim(3), GetDim(2), GetDim(1)); + // set up fluxes + for (int d = X1DIR; d <= n_outer; ++d) { + flux[d] = ParArrayND(Kokkos::subview(flux_data_, d - 1, Kokkos::ALL(), + Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL(), + Kokkos::ALL(), Kokkos::ALL())); + } } if (wpmb.expired()) return; - std::shared_ptr pmb = wpmb.lock(); - if (pmb->pmy_mesh->multilevel) + if (pmb->pmy_mesh != nullptr && pmb->pmy_mesh->multilevel) { coarse_s = ParArrayND(base_name + ".coarse", GetDim(6), GetDim(5), GetDim(4), pmb->c_cellbounds.ncellsk(IndexDomain::entire), pmb->c_cellbounds.ncellsj(IndexDomain::entire), pmb->c_cellbounds.ncellsi(IndexDomain::entire)); + } // Create the boundary object vbvar = std::make_shared(pmb, data, coarse_s, flux); diff --git a/src/interface/variable.hpp b/src/interface/variable.hpp index ee28145e26ad..4ef73d89658b 100644 --- a/src/interface/variable.hpp +++ b/src/interface/variable.hpp @@ -106,6 +106,7 @@ class CellVariable { private: Metadata m_; std::string label_; + ParArray7D flux_data_; // unified par array for the fluxes int sparse_id_; }; diff --git a/src/kokkos_abstraction.hpp b/src/kokkos_abstraction.hpp index 8e33a565d205..52cdf3761eba 100644 --- a/src/kokkos_abstraction.hpp +++ b/src/kokkos_abstraction.hpp @@ -67,6 +67,8 @@ template using ParArray5D = Kokkos::View; template using ParArray6D = Kokkos::View; +template +using ParArray7D = Kokkos::View; using team_policy = Kokkos::TeamPolicy<>; using team_mbr_t = Kokkos::TeamPolicy<>::member_type;