ttg 1.0.0
Template Task Graph (TTG): flowgraph-based programming model for high-performance distributed-memory algorithms
Loading...
Searching...
No Matches
simple.cc
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2#include <ttg.h>
3
4static void a(std::tuple<ttg::Out<int, double>> &out) {
5 ttg::print("Called task A ");
6
ttg::send<0>(0, 1.0, out);
8
ttg::send<0>(1, 2.0, out);
10}
11
12static void b(const int &key, const double &input, std::tuple<ttg::Out<void, double>, ttg::Out<void, double>> &out) {
13 ttg::print("Called task B(", key, ") with input data ", input);
14 if (key == 0)
ttg::sendv<0>(input + 1.0, out);
16 else
ttg::sendv<1>(input + 1.0, out);
18}
19
20static void c(const double &b0, const double &b1, std::tuple<> &out) {
21 ttg::print("Called task C with inputs ", b0, " from B(0) and ", b1, " from B(1)");
22}
23
24int main(int argc, char **argv) {
25 ttg::initialize(argc, argv, -1);
26
27 ttg::Edge<int, double> A_B("A->B");
28 ttg::Edge<void, double> B_C0("B->C0");
29 ttg::Edge<void, double> B_C1("B->C1");
30
31 auto wa(ttg::make_tt<void>(a, ttg::edges(), ttg::edges(A_B), "A", {}, {"to B"}));
32 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"}));
33 auto wc(ttg::make_tt(c, ttg::edges(B_C0, B_C1), ttg::edges(), "C", {"From B", "From B"}, {}));
34
36
37 if (wa->get_world().rank() == 0) wa->invoke();
38
41
43 return EXIT_SUCCESS;
44}
45
Edge is used to connect In and Out terminals.
Definition edge.h:26
int main(int argc, char **argv)
void execute(ttg::World world)
Starts the execution in the given execution context.
Definition run.h:116
void initialize(int argc, char **argv, int num_threads=-1, RestOfArgs &&...)
void send()
Sends a control message (message without an accompanying task id or a value) to the template tasks at...
Definition func.h:341
ttg::World & get_default_world()
Definition world.h:81
void fence(ttg::World world)
Returns when all tasks associated with the given execution context have finished on all ranks.
Definition run.h:123
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:180
void finalize()
Finalizes the TTG runtime.
Definition func.h:590
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:131
std::enable_if_t<(std::is_convertible_v< decltype(*(std::declval< TTBasePtrs >())), TTBase & > &&...), bool > make_graph_executable(TTBasePtrs &&...tts)
Make the TTG tts executable. Applies.
Definition func.h:81
auto edges(inedgesT &&...args)
Make a tuple of Edges to pass to.
Definition func.h:148