SingletonHelloWorld.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 /// \cond
7 /// [executable_example_includes]
8 #include "AlgorithmSingleton.hpp"
11 #include "Options/Options.hpp"
13 #include "Parallel/Info.hpp"
14 #include "Parallel/InitializationFunctions.hpp"
15 #include "Parallel/Invoke.hpp"
16 #include "Parallel/Printf.hpp"
17 /// [executable_example_includes]
18 
19 /// [executable_example_options]
20 namespace OptionTags {
21 struct Name {
22  using type = std::string;
23  static constexpr OptionString help{"A name"};
24 };
25 } // namespace OptionTags
26 /// [executable_example_options]
27 
28 /// [executable_example_action]
29 namespace Actions {
30 struct PrintMessage {
31  template <typename DbTags, typename... InboxTags, typename Metavariables,
32  typename ArrayIndex, typename ActionList,
33  typename ParallelComponent>
34  static void apply(db::DataBox<DbTags>& /*box*/,
37  const ArrayIndex& /*array_index*/,
38  const ActionList /*meta*/,
39  const ParallelComponent* const /*meta*/) {
40  Parallel::printf("Hello %s from process %d on node %d!\n",
41  Parallel::get<OptionTags::Name>(cache),
43  }
44 };
45 } // namespace Actions
46 /// [executable_example_action]
47 
48 /// [executable_example_singleton]
49 template <class Metavariables>
50 struct HelloWorld {
51  using const_global_cache_tag_list = tmpl::list<OptionTags::Name>;
52  using chare_type = Parallel::Algorithms::Singleton;
53  using metavariables = Metavariables;
54  using action_list = tmpl::list<>;
55  using initial_databox = db::DataBox<tmpl::list<>>;
56  using options = tmpl::list<>;
57  static void initialize(Parallel::CProxy_ConstGlobalCache<
58  Metavariables>& /* global_cache */) noexcept {}
59  static void execute_next_phase(
60  const typename Metavariables::Phase next_phase,
61  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache) noexcept;
62 };
63 
64 template <class Metavariables>
65 void HelloWorld<Metavariables>::execute_next_phase(
66  const typename Metavariables::Phase /* next_phase */,
67  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache) noexcept {
68  Parallel::simple_action<Actions::PrintMessage>(
69  Parallel::get_parallel_component<HelloWorld>(
70  *(global_cache.ckLocalBranch())));
71 }
72 /// [executable_example_singleton]
73 
74 /// [executable_example_metavariables]
75 struct Metavars {
76  using const_global_cache_tag_list = tmpl::list<>;
77 
78  using component_list = tmpl::list<HelloWorld<Metavars>>;
79 
80  static constexpr OptionString help{
81  "Say hello from a singleton parallel component."};
82 
83  enum class Phase { Initialization, Execute, Exit };
84 
85  static Phase determine_next_phase(const Phase& current_phase,
86  const Parallel::CProxy_ConstGlobalCache<
87  Metavars>& /*cache_proxy*/) noexcept {
88  return current_phase == Phase::Initialization ? Phase::Execute
89  : Phase::Exit;
90  }
91 };
92 /// [executable_example_metavariables]
93 
94 /// [executable_example_charm_init]
95 static const std::vector<void (*)()> charm_init_node_funcs{
96  &setup_error_handling};
97 static const std::vector<void (*)()> charm_init_proc_funcs{
99 /// [executable_example_charm_init]
100 /// \endcond
Defines functions for interfacing with the parallelization framework.
Items for initializing the DataBoxes of parallel components.
Definition: ConservativeSystem.hpp:21
Defines classes and functions for making classes creatable from input files.
int my_proc()
Index of my processing element.
Definition: Info.hpp:22
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args)
Apply the function f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1595
int my_node()
Index of my node.
Definition: Info.hpp:34
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:27
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
Defines classes and functions used for manipulating DataBox&#39;s.
void enable_floating_point_exceptions()
After a call to this function, the code will terminate with a floating point exception on overflow...
Definition: FloatingPointExceptions.cpp:27
Defines Parallel::printf for writing to stdout.
Definition: Strahlkorper.hpp:167
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Functions to enable/disable termination on floating point exceptions.
Definition: SolvePoissonProblem.hpp:38
Defines class template ConstGlobalCache.
void printf(const std::string &format, Args &&... args)
Print an atomic message to stdout with C printf usage.
Definition: Printf.hpp:100
Definition: ComputeTimeDerivative.hpp:28