Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include "DataStructures/DataBox/Protocols/Mutator.hpp"
7 : #include "Parallel/Algorithms/AlgorithmSingletonDeclarations.hpp"
8 : #include "Parallel/GlobalCache.hpp"
9 : #include "Parallel/Local.hpp"
10 : #include "Parallel/MemoryMonitor/Tags.hpp"
11 : #include "Parallel/ParallelComponentHelpers.hpp"
12 : #include "Parallel/Phase.hpp"
13 : #include "ParallelAlgorithms/Actions/AddSimpleTags.hpp"
14 : #include "ParallelAlgorithms/Actions/TerminatePhase.hpp"
15 : #include "Utilities/Gsl.hpp"
16 : #include "Utilities/ProtocolHelpers.hpp"
17 : #include "Utilities/TMPL.hpp"
18 :
19 : /*!
20 : * \ingroup ParallelGroup
21 : * Holds the MemoryMonitor parallel component and all actions and tags related
22 : * to the memory monitor.
23 : */
24 1 : namespace mem_monitor {}
25 :
26 : namespace mem_monitor {
27 : namespace detail {
28 : struct InitializeMutator : tt::ConformsTo<db::protocols::Mutator> {
29 : using return_tags = tmpl::list<mem_monitor::Tags::MemoryHolder>;
30 : using argument_tags = tmpl::list<>;
31 :
32 : using tag_type = typename mem_monitor::Tags::MemoryHolder::type;
33 :
34 : static void apply(const gsl::not_null<tag_type*> /*holder*/) {}
35 : };
36 : } // namespace detail
37 :
38 : /*!
39 : * \brief Singleton parallel component used for monitoring memory usage of other
40 : * parallel components
41 : */
42 : template <class Metavariables>
43 1 : struct MemoryMonitor {
44 0 : using chare_type = Parallel::Algorithms::Singleton;
45 0 : static constexpr bool checkpoint_data = true;
46 :
47 0 : using metavariables = Metavariables;
48 :
49 0 : using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
50 : Parallel::Phase::Initialization,
51 : tmpl::list<Initialization::Actions::AddSimpleTags<
52 : mem_monitor::detail::InitializeMutator>,
53 : Parallel::Actions::TerminatePhase>>>;
54 :
55 0 : using simple_tags_from_options = Parallel::get_simple_tags_from_options<
56 : Parallel::get_initialization_actions_list<phase_dependent_action_list>>;
57 :
58 0 : static void execute_next_phase(
59 : const Parallel::Phase next_phase,
60 : Parallel::CProxy_GlobalCache<Metavariables>& global_cache) {
61 : auto& local_cache = *Parallel::local_branch(global_cache);
62 : Parallel::get_parallel_component<MemoryMonitor<Metavariables>>(local_cache)
63 : .start_phase(next_phase);
64 : }
65 : };
66 : } // namespace mem_monitor
|