ttg 1.0.0
Template Task Graph (TTG): flowgraph-based programming model for high-performance distributed-memory algorithms
Loading...
Searching...
No Matches
terminal.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2#ifndef TTG_BASE_TERMINAL_H
3#define TTG_BASE_TERMINAL_H
4
5#include <string>
6#include <vector>
7#include "ttg/fwd.h"
8
9namespace ttg {
10
14 public:
15 static constexpr bool is_a_terminal = true;
16 bool is_pull_terminal = false; //< Default is push terminal
17
19 enum class Type {
20 Write,
21 Read,
22 Consume
23 };
24
25 private:
26 TTBase *tt; //< Pointer to containing operation
27 size_t n = 0; //< Index of terminal
28 std::string name = ""; //< Name of terminal
29 bool connected = false; //< True if is connected
30 Type type;
31 std::string key_type_str; //< String describing key type
32 std::string value_type_str; //< String describing value type
33
34 std::vector<TerminalBase *> successors_;
35 std::vector<TerminalBase *> predecessors_; //This is required for pull terminals.
36
37 TerminalBase(const TerminalBase &) = delete;
38 TerminalBase(TerminalBase &&) = delete;
39
40 friend class TTBase;
41 template <typename keyT, typename valueT>
42 friend class In;
43 template <typename keyT, typename valueT>
44 friend class Out;
45
46 protected:
47 TerminalBase(Type type) : type(type) {}
48
49 void set(TTBase *tt, size_t index, const std::string &name, const std::string &key_type_str,
50 const std::string &value_type_str, Type type) {
51 this->tt = tt;
52 this->n = index;
53 this->name = name;
54 this->key_type_str = key_type_str;
55 this->value_type_str = value_type_str;
56 this->type = type;
57 }
58
61 void connect_base(TerminalBase *successor) {
62 successors_.push_back(successor);
63 connected = true;
64 successor->connected = true;
65 }
66
67 void connect_pull(TerminalBase *predecessor) {
68 predecessors_.push_back(predecessor);
69 predecessor->connected = true;
70 connected = true;
71 }
72
73 public:
75 TTBase *get_tt() const {
76 if (!tt) throw "ttg::TerminalBase:get_tt() but tt is null";
77 return tt;
78 }
79
81 size_t get_index() const {
82 if (!tt) throw "ttg::TerminalBase:get_index() but tt is null";
83 return n;
84 }
85
87 const std::string &get_name() const {
88 if (!tt) throw "ttg::TerminalBase:get_name() but tt is null";
89 return name;
90 }
91
93 const std::string &get_key_type_str() const {
94 if (!tt) throw "ttg::TerminalBase:get_key_type_str() but tt is null";
95 return key_type_str;
96 }
97
99 const std::string &get_value_type_str() const {
100 if (!tt) throw "ttg::TerminalBase:get_value_type_str() but tt is null";
101 return value_type_str;
102 }
103
105 Type get_type() const { return this->type; }
106
108 const std::vector<TerminalBase *> &get_connections() const { return successors_; }
109 // Get connections to predecessors
110 const std::vector<TerminalBase *> &get_predecessors() const {return predecessors_; }
111
112 //Connect Container pull terminals without incoming terminals
113 //This is a hack, is there a better way?
115 p->connected = true;
116 }
117
119 bool is_connected() const { return connected; }
120
125 virtual void connect(TerminalBase *in) = 0;
126
127 virtual ~TerminalBase() = default;
128 };
129
130 namespace meta {
131 template <typename T, typename = void>
132 inline constexpr bool is_terminal_v = false;
133 template <typename T>
134 inline constexpr bool is_terminal_v<T, std::is_base_of<TerminalBase, T>> = true;
135 template <typename T>
136 struct is_terminal : std::bool_constant<is_terminal_v<T>> {};
137 } // namespace meta
138} // namespace ttg
139
140#endif // TTG_BASE_TERMINAL_H
A base class for all template tasks.
Definition tt.h:32
const std::vector< TerminalBase * > & get_predecessors() const
Definition terminal.h:110
static constexpr bool is_a_terminal
Definition terminal.h:15
bool is_connected() const
Returns true if this terminal (input or output) is connected.
Definition terminal.h:119
TTBase * get_tt() const
Return ptr to containing tt.
Definition terminal.h:75
bool is_pull_terminal
Definition terminal.h:16
size_t get_index() const
Returns index of terminal.
Definition terminal.h:81
virtual void connect(TerminalBase *in)=0
void connect_base(TerminalBase *successor)
Definition terminal.h:61
const std::string & get_key_type_str() const
Returns string representation of key type.
Definition terminal.h:93
Type get_type() const
Returns the terminal type.
Definition terminal.h:105
void connect_pull_nopred(TerminalBase *p)
Definition terminal.h:114
void set(TTBase *tt, size_t index, const std::string &name, const std::string &key_type_str, const std::string &value_type_str, Type type)
Definition terminal.h:49
const std::string & get_value_type_str() const
Returns string representation of value type.
Definition terminal.h:99
virtual ~TerminalBase()=default
TerminalBase(Type type)
Definition terminal.h:47
void connect_pull(TerminalBase *predecessor)
Definition terminal.h:67
const std::vector< TerminalBase * > & get_connections() const
Get connections to successors.
Definition terminal.h:108
const std::string & get_name() const
Returns name of terminal.
Definition terminal.h:87
Type
describes the terminal type
Definition terminal.h:19
@ Write
can only be written to
@ Read
can only be used to read immutable data
@ Consume
can only be used to read consumable data
constexpr bool is_terminal_v
Definition terminal.h:132
constexpr auto get(typelist< T, RestOfTs... >)
Definition typelist.h:102
top-level TTG namespace contains runtime-neutral functionality
Definition keymap.h:9