Itoyori  v0.0.1
ityr.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ityr/common/util.hpp"
8 #include "ityr/ito/ito.hpp"
9 #include "ityr/ori/ori.hpp"
20 #include "ityr/pattern/random.hpp"
27 
28 namespace ityr {
29 
30 namespace internal {
31 
32 class ityr {
33 public:
34  ityr(MPI_Comm comm)
35  : mi_(comm),
36  topo_(comm),
37  ito_(comm),
38  ori_(comm) {}
39 
40 private:
41  common::mpi_initializer mi_;
42  common::runtime_options opts_;
43  common::singleton_initializer<common::topology::instance> topo_;
44  common::singleton_initializer<common::wallclock::instance> clock_;
45  common::singleton_initializer<common::profiler::instance> prof_;
46  common::singleton_initializer<ito::instance> ito_;
47  common::singleton_initializer<ori::instance> ori_;
48 };
49 
50 using instance = common::singleton<ityr>;
51 
52 }
53 
69 inline void init(MPI_Comm comm = MPI_COMM_WORLD) {
71 }
72 
84 inline void fini() {
86 }
87 
94 
99 inline rank_t my_rank() {
100  return common::topology::my_rank();
101 }
102 
107 inline rank_t n_ranks() {
108  return common::topology::n_ranks();
109 }
110 
115 inline bool is_master() {
116  return my_rank() == 0;
117 }
118 
122 inline bool is_root() {
123  return ito::is_root();
124 }
125 
129 inline void migrate_to(rank_t target_rank) {
130  ito::migrate_to(target_rank, [] { ori::release(); }, [] { ori::acquire(); });
131 }
132 
136 inline void migrate_to_master() {
137  ito::migrate_to(0, [] { ori::release(); }, [] { ori::acquire(); });
138 }
139 
143 inline bool is_spmd() {
144  return ito::is_spmd();
145 }
146 
150 inline void barrier() {
151  ITYR_CHECK(is_spmd());
152  ori::release();
154  ori::acquire();
155 }
156 
162 
173 }
174 
180 inline void profiler_begin() {
181  ITYR_CHECK(is_spmd());
185 #if ITYR_DEBUG_UCX
186  common::ityr_ucx_log_enable(1);
187  ucs_info("Itoyori profiler begin");
188 #endif
189 }
190 
196 inline void profiler_end() {
197  ITYR_CHECK(is_spmd());
198 #if ITYR_DEBUG_UCX
199  ucs_info("Itoyori profiler end");
200  common::ityr_ucx_log_enable(0);
201 #endif
205 }
206 
212 inline void profiler_flush() {
213  ITYR_CHECK(is_spmd());
214 #if ITYR_DEBUG_UCX
215  common::ityr_ucx_log_flush();
216 #endif
220 }
221 
226 inline void print_compile_options() {
230 }
231 
236 inline void print_runtime_options() {
238 }
239 
240 }
static void init(Args &&... args)
Definition: util.hpp:190
static void fini()
Definition: util.hpp:194
#define ITYR_CHECK(cond)
Definition: util.hpp:48
void end()
Definition: profiler.hpp:334
singleton< profiler< mode > > instance
Definition: profiler.hpp:259
void begin()
Definition: profiler.hpp:329
void flush()
Definition: profiler.hpp:338
rank_t n_ranks()
Definition: topology.hpp:208
int rank_t
Definition: topology.hpp:12
MPI_Comm mpicomm()
Definition: topology.hpp:206
rank_t my_rank()
Definition: topology.hpp:207
uint64_t wallclock_t
Definition: wallclock.hpp:13
wallclock_t gettime_ns()
Definition: wallclock.hpp:88
void print_runtime_options()
Definition: options.hpp:111
void print_compile_options()
Definition: options.hpp:16
void mpi_barrier(MPI_Comm comm)
Definition: mpi_util.hpp:42
void print_compile_options()
Definition: options.hpp:8
void migrate_to(common::topology::rank_t target_rank, PreSuspendCallback &&pre_suspend_cb, PostSuspendCallback &&post_suspend_cb)
Definition: ito.hpp:80
void dag_prof_print()
Definition: ito.hpp:132
bool is_root()
Definition: ito.hpp:66
bool is_spmd()
Definition: ito.hpp:61
void dag_prof_begin()
Definition: ito.hpp:120
void dag_prof_end()
Definition: ito.hpp:126
void cache_prof_begin()
Definition: ori.hpp:232
void print_compile_options()
Definition: options.hpp:8
void release()
Definition: ori.hpp:196
void cache_prof_print()
Definition: ori.hpp:240
void cache_prof_end()
Definition: ori.hpp:236
void acquire()
Definition: ori.hpp:206
Definition: allocator.hpp:16
bool is_spmd()
Return true if the current execution context is within the SPMD region.
Definition: ityr.hpp:143
rank_t my_rank()
Return the rank of the process running the current thread.
Definition: ityr.hpp:99
void profiler_end()
Stop the profiler (collective).
Definition: ityr.hpp:196
void print_runtime_options()
Print the runtime options to stdout.
Definition: ityr.hpp:236
bool is_master()
Return true if ityr::my_rank() == 0.
Definition: ityr.hpp:115
wallclock_t gettime_ns()
Return the current wallclock time in nanoseconds.
Definition: ityr.hpp:171
void profiler_begin()
Start the profiler (collective).
Definition: ityr.hpp:180
void print_compile_options()
Print the compile-time options to stdout.
Definition: ityr.hpp:226
rank_t n_ranks()
Return the total number of processes.
Definition: ityr.hpp:107
void fini()
Finalize Itoyori (collective).
Definition: ityr.hpp:84
void migrate_to(rank_t target_rank)
Migrate the current thread to target_rank. For the root thread only.
Definition: ityr.hpp:129
bool is_root()
Return true if the current thread is the root thread.
Definition: ityr.hpp:122
void migrate_to_master()
Migrate the current thread to the master worker (of rank 0).
Definition: ityr.hpp:136
void init(MPI_Comm comm=MPI_COMM_WORLD)
Initialize Itoyori (collective).
Definition: ityr.hpp:69
void barrier()
Barrier for all processes (collective).
Definition: ityr.hpp:150
common::topology::rank_t rank_t
Process rank (ID) starting from 0 (corresponding to an MPI rank).
Definition: ityr.hpp:93
void profiler_flush()
Print the profiled results to stdout (collective).
Definition: ityr.hpp:212
common::wallclock::wallclock_t wallclock_t
Wallclock time in nanoseconds.
Definition: ityr.hpp:161