simple.cc
Go to the documentation of this file.
1 #include <ttg.h>
2 
3 static void a(std::tuple<ttg::Out<int, double>> &out) {
4  ttg::print("Called task A ");
5  ttg::send<0>(0, 1.0, out);
7  ttg::send<0>(1, 2.0, out);
9 }
10 
11 static void b(const int &key, const double &input, std::tuple<ttg::Out<void, double>, ttg::Out<void, double>> &out) {
12  ttg::print("Called task B(", key, ") with input data ", input);
13  if (key == 0) ttg::sendv<0>(input + 1.0, out);
15  else ttg::sendv<1>(input + 1.0, out);
17 }
18 
19 static void c(const double &b0, const double &b1, std::tuple<> &out) {
20  ttg::print("Called task C with inputs ", b0, " from B(0) and ", b1, " from B(1)");
21 }
22 
23 int main(int argc, char **argv) {
24  ttg::initialize(argc, argv, -1);
25 
26  ttg::Edge<int, double> A_B("A->B");
27  ttg::Edge<void, double> B_C0("B->C0");
28  ttg::Edge<void, double> B_C1("B->C1");
29 
30  auto wa(ttg::make_tt<void>(a, ttg::edges(), ttg::edges(A_B), "A", {}, {"to B"}));
31  auto wb(ttg::make_tt(b, ttg::edges(A_B), ttg::edges(B_C0, B_C1), "B", {"from A"}, {"to 1st input of C", "to 2nd input of C"}));
32  auto wc(ttg::make_tt(c, ttg::edges(B_C0, B_C1), ttg::edges(), "C", {"From B", "From B"}, {}));
33 
35 
36  if (wa->get_world().rank() == 0) wa->invoke();
37 
38  ttg::execute();
40 
41  ttg::finalize();
42  return EXIT_SUCCESS;
43 }
44 
Edge is used to connect In and Out terminals.
Definition: edge.h:25
auto make_tt(funcT &&func, const std::tuple< ttg::Edge< keyT, input_edge_valuesT >... > &inedges=std::tuple<>{}, const std::tuple< output_edgesT... > &outedges=std::tuple<>{}, const std::string &name="wrapper", const std::vector< std::string > &innames=std::vector< std::string >(sizeof...(input_edge_valuesT), "input"), const std::vector< std::string > &outnames=std::vector< std::string >(sizeof...(output_edgesT), "output"))
Factory function to assist in wrapping a callable with signature.
Definition: make_tt.h:496
void execute(ttg::World world)
Starts the execution in the given execution context.
Definition: run.h:74
void send(const keyT &key, valueT &&value, ttg::Out< keyT, valueT > &t)
Sends a task id and a value to the given output terminal.
Definition: func.h:158
void initialize(int argc, char **argv, int num_threads=-1, RestOfArgs &&...)
std::enable_if_t<(std::is_convertible_v< decltype(*(std::declval< TTBasePtrs >))), TTBase & > bool make_graph_executable(TTBasePtrs &&...tts)
Definition: func.h:80
void fence(ttg::World world)
Returns when all tasks associated with the given execution context have finished on all ranks.
Definition: run.h:81
void sendv(valueT &&value, ttg::Out< void, valueT > &t)
Sends a value (without an accompanying task id) to the given output terminal.
Definition: func.h:179
void print(const T &t, const Ts &... ts)
atomically prints to std::cout a sequence of items (separated by ttg::print_separator) followed by st...
Definition: print.h:130
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
ttg::World & get_default_world()
Definition: world.h:80
auto edges(inedgesT &&...args)
Make a tuple of Edges to pass to.
Definition: func.h:147
int main(int argc, char **argv)
Definition: simple.cc:23