run.h
Go to the documentation of this file.
1 //
2 // Created by Eduard Valeyev on 11/5/21.
3 //
4 
5 #ifndef TTG_RUN_H
6 #define TTG_RUN_H
7 
8 #include "ttg/fwd.h"
9 
10 #include "ttg/util/bug.h"
11 #include "ttg/util/env.h"
12 #include "ttg/world.h"
13 
14 namespace ttg {
15 
17 
30  template <typename... RestOfArgs>
31  inline void initialize(int argc, char** argv, int num_threads, RestOfArgs&&... args) {
32  // if requested by user, create a Debugger object
33  if (auto debugger_cstr = std::getenv("TTG_DEBUGGER")) {
34  using ttg::Debugger;
35  auto debugger = std::make_shared<Debugger>();
37  debugger->set_exec(argv[0]);
38  debugger->set_cmd(debugger_cstr);
39  }
40 
42  TTG_IMPL_NS::ttg_initialize(argc, argv, num_threads, std::forward<RestOfArgs>(args)...);
43 
44  // finish setting up the Debugger, if needed
47  }
48 
50 
58  inline void finalize() { TTG_IMPL_NS::ttg_finalize(); }
59 
61  [[noreturn]]
62  inline void abort() { TTG_IMPL_NS::ttg_abort(); }
63 
65 
69 
71 
75 
77 
81  inline void fence(World world = default_execution_context()) { TTG_IMPL_NS::ttg_fence(world); }
82 
85  inline int rank(World world = default_execution_context()) { return world.rank(); }
86 
89  inline int size(World world = default_execution_context()) { return world.size(); }
90 
96  template <typename TT>
97  inline void invoke_once(TT& tt) {
98  if (tt.keymap() == tt.get_world().rank()) {
99  tt.invoke();
100  }
101  }
102 
109  template <typename TT, typename Key>
110  inline void invoke_once(TT&& tt, Key&& key) {
111  if (tt.keymap(key) == tt.get_world().rank()) {
112  tt.invoke(std::forward<Key>(key));
113  }
114  }
115 
116 } // namespace ttg
117 
118 #endif // TTG_RUN_H
static void set_default_debugger(const std::shared_ptr< Debugger > &)
Set the global default debugger. The initial value is null.
Definition: bug.cpp:406
static std::shared_ptr< Debugger > default_debugger()
Return the global default debugger.
Definition: bug.cpp:408
int rank() const
Definition: world.h:204
std::enable_if_t<!ttg::meta::is_void_v< Key > &&!ttg::meta::is_empty_tuple_v< input_values_tuple_type >, void > invoke(const Key &key, const input_values_tuple_type &args)
Definition: ttg.h:4218
ttg::World get_world() const override final
Definition: ttg.h:1351
int num_threads()
Determine the number of compute threads to use by TTG when not given to ttg::initialize
Definition: env.cpp:15
void ttg_initialize(int argc, char **argv, int num_threads=-1)
Definition: ttg.h:124
void ttg_execute(ttg::World world)
Definition: ttg.h:142
void ttg_fence(ttg::World world)
Definition: ttg.h:145
void ttg_finalize()
Definition: ttg.h:132
void ttg_abort()
Definition: ttg.h:138
ttg::World ttg_default_execution_context()
Definition: ttg.h:137
top-level TTG namespace contains runtime-neutral functionality
Definition: keymap.h:8
void invoke_once(TT &tt)
Definition: run.h:97
void execute(ttg::World world)
Starts the execution in the given execution context.
Definition: run.h:74
void initialize(int argc, char **argv, int num_threads=-1, RestOfArgs &&...)
int size(World world=default_execution_context())
Definition: run.h:89
void abort()
Aborts the TTG program using the default backend's ttg_abort method.
Definition: run.h:62
World default_execution_context()
Accesses the default backend's default execution context.
Definition: run.h:68
void fence(ttg::World world)
Returns when all tasks associated with the given execution context have finished on all ranks.
Definition: run.h:81
int rank(World world=default_execution_context())
Definition: run.h:85
std::enable_if_t<!meta::is_void_v< keyT >, void > finalize(const keyT &key, ttg::Out< out_keyT, out_valueT > &t)
Finalize streaming input terminals connecting to the given output terminal for tasks identified by ke...
Definition: func.h:543