Skip to content

Commit

Permalink
Merge pull request #6040 from nilsdeppe/add_threading_15
Browse files Browse the repository at this point in the history
Add ElementLocationsReference tag, and TransformPdalForNodegroup metafunction
  • Loading branch information
kidder authored May 31, 2024
2 parents c9e1af7 + 2d4ca06 commit daaaaf4
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Parallel/ArrayCollection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spectre_target_headers(
SetTerminateOnElement.hpp
SpawnInitializeElementsInCollection.hpp
StartPhaseOnNodegroup.hpp
TransformPdalForNodegroup.hpp
)

spectre_target_sources(
Expand Down
1 change: 1 addition & 0 deletions src/Parallel/ArrayCollection/Tags/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ spectre_target_headers(
HEADERS
ElementCollection.hpp
ElementLocations.hpp
ElementLocationsReference.hpp
NumberOfElementsTerminated.hpp
)
9 changes: 0 additions & 9 deletions src/Parallel/ArrayCollection/Tags/ElementLocations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,4 @@ template <size_t Dim>
struct ElementLocations : db::SimpleTag {
using type = std::unordered_map<ElementId<Dim>, size_t>;
};

/// \brief The node (location) where different elements are.
///
/// This should be in the DgElementArrayMember's DataBox and should point to
/// the one located in the nodegroup's DataBox.
template <size_t Dim>
struct ElementLocationsPointer : db::SimpleTag {
using type = std::unordered_map<ElementId<Dim>, size_t>*;
};
} // namespace Parallel::Tags
59 changes: 59 additions & 0 deletions src/Parallel/ArrayCollection/Tags/ElementLocationsReference.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#pragma once

#include <cstddef>
#include <unordered_map>

#include "DataStructures/DataBox/Tag.hpp"
#include "Parallel/ArrayCollection/Tags/ElementLocations.hpp"
#include "Parallel/GlobalCache.hpp"
#include "Parallel/Invoke.hpp"
#include "Utilities/Gsl.hpp"

/// \cond
template <size_t Dim>
class ElementId;
namespace Parallel {
class NodeLock;
} // namespace Parallel
/// \endcond

namespace Parallel::Tags {
/// \brief The node (location) where different elements are.
///
/// This should be in the DgElementArrayMember's DataBox.
///
/// Implementation note: This should point to the ElementLocations located in
/// the nodegroup's DataBox.
template <size_t Dim, typename Metavariables,
typename DgElementCollectionComponent>
struct ElementLocationsReference : ElementLocations<Dim>, db::ReferenceTag {
private:
struct GetReference {
using return_type = const typename ElementLocations<Dim>::type&;

template <typename ParallelComponent, typename DbTagList>
static return_type apply(
db::DataBox<DbTagList>& box,
const gsl::not_null<Parallel::NodeLock*> /*node_lock*/) {
return db::get_mutable_reference<ElementLocations<Dim>>(
make_not_null(&box));
}
};

public:
using base = ElementLocations<Dim>;
using type = typename base::type;
using argument_tags =
tmpl::list<Parallel::Tags::GlobalCacheImpl<Metavariables>>;

static const type& get(
const Parallel::GlobalCache<Metavariables>* const& cache) {
auto& parallel_comp =
Parallel::get_parallel_component<DgElementCollectionComponent>(*cache);
return Parallel::local_synchronous_action<GetReference>(parallel_comp);
}
};
} // namespace Parallel::Tags
29 changes: 29 additions & 0 deletions src/Parallel/ArrayCollection/TransformPdalForNodegroup.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#pragma once

#include "Parallel/ArrayCollection/StartPhaseOnNodegroup.hpp"
#include "Parallel/Phase.hpp"
#include "Parallel/PhaseDependentActionList.hpp"
#include "Utilities/TMPL.hpp"

namespace Parallel {
namespace detail {
template <typename OnePhaseActions>
struct TransformPdalForNodegroup {
using type = tmpl::conditional_t<
OnePhaseActions::phase == Parallel::Phase::Initialization, tmpl::list<>,
Parallel::PhaseActions<OnePhaseActions::phase,
tmpl::list<Actions::StartPhaseOnNodegroup>>>;
};
} // namespace detail

/// \brief Transforms the `PhaseDepActionList` (phase dependent action
/// list/PDAL) from one used for a `evolution::DgElementArray` to that for
/// `Parallel::DgElementCollection`
template <typename PhaseDepActionList>
using TransformPhaseDependentActionListForNodegroup =
tmpl::flatten<tmpl::transform<PhaseDepActionList,
detail::TransformPdalForNodegroup<tmpl::_1>>>;
} // namespace Parallel
5 changes: 3 additions & 2 deletions tests/Unit/Parallel/ArrayCollection/Test_Tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Helpers/DataStructures/DataBox/TestHelpers.hpp"
#include "Parallel/ArrayCollection/Tags/ElementCollection.hpp"
#include "Parallel/ArrayCollection/Tags/ElementLocations.hpp"
#include "Parallel/ArrayCollection/Tags/ElementLocationsReference.hpp"
#include "Parallel/ArrayCollection/Tags/NumberOfElementsTerminated.hpp"

namespace Parallel {
Expand All @@ -16,8 +17,8 @@ SPECTRE_TEST_CASE("Unit.Parallel.ArrayCollection.Tags", "[Unit][Parallel]") {
Tags::ElementCollection<3, void, void, void>>("ElementCollection");
TestHelpers::db::test_simple_tag<Tags::ElementLocations<3>>(
"ElementLocations");
TestHelpers::db::test_simple_tag<Tags::ElementLocationsPointer<3>>(
"ElementLocationsPointer");
TestHelpers::db::test_reference_tag<
Tags::ElementLocationsReference<3, void, void>>("ElementLocations");
TestHelpers::db::test_simple_tag<Tags::NumberOfElementsTerminated>(
"NumberOfElementsTerminated");
}
Expand Down

0 comments on commit daaaaf4

Please sign in to comment.