ttg 1.0.0
Template Task Graph (TTG): flowgraph-based programming model for high-performance distributed-memory algorithms
Loading...
Searching...
No Matches
broadcast.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// Created by Eduard Valeyev on 12/29/17.
4//
5
6#ifndef TTG_BROADCAST_H
7#define TTG_BROADCAST_H
8
9#include <tuple>
10
11#include "ttg/func.h"
12#include "ttg/fwd.h"
13#include "ttg/tt.h"
14#include "ttg/util/tree.h"
15#include "ttg/world.h"
16
17namespace ttg {
18
28 template <typename Value, typename OutKey = int>
29 class BinaryTreeBroadcast : public TT<int, std::tuple<Out<int, Value>, Out<int, Value>, Out<OutKey, Value>>,
30 BinaryTreeBroadcast<Value, OutKey>, ttg::typelist<Value>> {
31 public:
33
37 : baseT(edges(fuse(in, inout_l, inout_r)), edges(inout_l, inout_r, out), "BinaryTreeBroadcast",
38 {"in|inout_l|inout_r"}, {"inout_l", "inout_r", "out"}, world, [](int key) { return key; })
39 , tree_((max_key == -1 ? world.size() : max_key), root)
40 , local_keys_(std::move(local_keys)) {}
41
42 void op(const int &key, typename baseT::input_values_tuple_type &&indata,
44 assert(key < tree_.size());
45 assert(key == this->get_world().rank());
46 auto children = tree_.child_keys(key);
47 if (children.first != -1) send<0>(children.first, this->template get<0, const Value &>(indata), outdata);
48 if (children.second != -1) send<1>(children.second, this->template get<0, const Value &>(indata), outdata);
49 broadcast<2>(local_keys_, this->template get<0, const Value &>(indata), outdata);
50 }
51
52 private:
54 std::vector<OutKey> local_keys_;
55 };
56
57} // namespace ttg
58
59#endif // TTG_BROADCAST_H
a binary spanning tree of integers in the [0,size) interval
Definition tree.h:18
const auto size() const
Definition tree.h:27
std::pair< int, int > child_keys(const int parent_key) const
Definition tree.h:41
generic binary broadcast of a value to a set of {key,value} pairs
Definition broadcast.h:30
typename BinaryTreeBroadcast::ttT baseT
Definition broadcast.h:32
void op(const int &key, typename baseT::input_values_tuple_type &&indata, std::tuple< Out< int, Value >, Out< int, Value >, Out< int, Value > > &outdata)
Definition broadcast.h:42
BinaryTreeBroadcast(Edge< int, Value > &in, Edge< OutKey, Value > &out, std::vector< OutKey > local_keys, int root=0, World world=ttg::default_execution_context(), int max_key=-1, Edge< int, Value > inout_l=Edge< int, Value >{}, Edge< int, Value > inout_r=Edge< int, Value >{})
Definition broadcast.h:34
Edge is used to connect In and Out terminals.
Definition edge.h:26
ttg::World get_world() const override final
Definition ttg.h:1373
std::tuple_element_t< i, output_terminalsT > * out()
Definition ttg.h:4299
std::tuple_element_t< i, input_terminals_type > * in()
Definition ttg.h:4292
static resultT get(InTuple &&intuple)
Definition ttg.h:1293
top-level TTG namespace contains runtime-neutral functionality
Definition keymap.h:9
auto fuse(const Edge< keyT, valuesT > &...args)
Fuse edges into one This allows receiving one data from either of the combined edges.
Definition func.h:138
World default_execution_context()
Accesses the default backend's default execution context.
Definition run.h:110
int rank(World world=default_execution_context())
Definition run.h:127
auto edges(inedgesT &&...args)
Make a tuple of Edges to pass to.
Definition func.h:148