44inline constexpr std::array<TaskType, 7> TASK_TYPES = {
78 default: val =
"undefined";
break;
95 std::same_as<std::invoke_result_t<C>,
void>;
118 std::same_as<std::invoke_result_t<C, tf::Subflow&>,
void>;
142 (std::invocable<C, tf::Runtime&> &&
143 std::same_as<std::invoke_result_t<C, tf::Runtime&>,
void>) ||
144 (std::invocable<C, tf::NonpreemptiveRuntime&> &&
145 std::same_as<std::invoke_result_t<C, tf::NonpreemptiveRuntime&>,
void>);
169 std::convertible_to<std::invoke_result_t<C>,
int>;
265 friend class FlowBuilder;
266 friend class Runtime;
267 friend class NonpreemptiveRuntime;
268 friend class Taskflow;
269 friend class TaskView;
270 friend class Executor;
357 const std::string&
name()
const;
481 template <
typename C>
501 template <GraphLike T>
546 template <
typename... Ts>
568 template <
typename... Ts>
598 template <
typename... Ts>
628 template <
typename... Ts>
645 template <
typename I>
662 template <
typename I>
768 template <
typename V>
792 template <
typename V>
815 template <
typename V>
855 void dump(std::ostream& ostream)
const;
939 Node* _node {
nullptr};
951template <
typename... Ts>
953 (_node->_precede(tasks._node), ...);
959template <
typename... Ts>
961 (tasks._node->_precede(_node), ...);
967template <
typename... Ts>
969 (tasks._node->_remove_successors(_node), ...);
970 (_node->_remove_predecessors(tasks._node), ...);
975template <
typename... Ts>
977 (_node->_remove_successors(tasks._node), ...);
978 (tasks._node->_remove_predecessors(_node), ...);
983template <GraphLike T>
991 _node->_handle.emplace<Node::AdoptedModule>(std::move(graph));
1009 return _node == rhs._node;
1014 return _node != rhs._node;
1019 _node->_name =
name;
1025 if(!_node->_semaphores) {
1026 _node->_semaphores = std::make_unique<Node::Semaphores>();
1028 _node->_semaphores->to_acquire.push_back(&s);
1033template <
typename I>
1035 if(!_node->_semaphores) {
1036 _node->_semaphores = std::make_unique<Node::Semaphores>();
1038 _node->_semaphores->to_acquire.reserve(
1039 _node->_semaphores->to_acquire.size() + std::distance(first, last)
1041 for(
auto s = first; s != last; ++s){
1042 _node->_semaphores->to_acquire.push_back(&(*s));
1049 if(!_node->_semaphores) {
1050 _node->_semaphores = std::make_unique<Node::Semaphores>();
1052 _node->_semaphores->to_release.push_back(&s);
1057template <
typename I>
1059 if(!_node->_semaphores) {
1060 _node->_semaphores = std::make_unique<Node::Semaphores>();
1062 _node->_semaphores->to_release.reserve(
1063 _node->_semaphores->to_release.size() + std::distance(first, last)
1065 for(
auto s = first; s != last; ++s) {
1066 _node->_semaphores->to_release.push_back(&(*s));
1078 _node->_handle.emplace<std::monostate>();
1083 return _node->_name;
1093 return _node->num_strong_dependencies();
1098 return _node->num_weak_dependencies();
1103 return _node->num_successors();
1108 return _node ==
nullptr;
1113 return _node ? _node->_handle.index() != 0 :
false;
1118 return _node ? _node->_exception_ptr :
nullptr;
1123 return _node ? (_node->_exception_ptr !=
nullptr) :
false;
1128 switch(_node->_handle.index()) {
1145template <
typename V>
1147 for(
size_t i=0; i<_node->_num_successors; ++i) {
1148 visitor(
Task(_node->_edges[i]));
1153template <
typename V>
1155 for(
size_t i=_node->_num_successors; i<_node->_edges.size(); ++i) {
1156 visitor(
Task(_node->_edges[i]));
1161template <
typename V>
1163 if(
auto ptr = std::get_if<Node::Subflow>(&_node->_handle); ptr) {
1164 for(
auto itr = ptr->subgraph.begin(); itr != ptr->subgraph.end(); ++itr) {
1165 visitor(
Task(*itr));
1172 return std::hash<Node*>{}(_node);
1184template <
typename C>
1188 _node->_handle.emplace<Node::Static>(std::forward<C>(c));
1191 _node->_handle.emplace<Node::Runtime>(std::forward<C>(c));
1194 _node->_handle.emplace<Node::Subflow>(std::forward<C>(c));
1197 _node->_handle.emplace<Node::Condition>(std::forward<C>(c));
1200 _node->_handle.emplace<Node::MultiCondition>(std::forward<C>(c));
1203 static_assert(dependent_false_v<C>,
"invalid task callable");
1210 return _node->_data;
1215 _node->_data =
data;
1242 friend class Executor;
1249 const std::string&
name()
const;
1279 template <
typename V>
1290 template <
typename V>
1305 TaskView(
const Node&);
1306 TaskView(
const TaskView&) =
default;
1312inline TaskView::TaskView(
const Node& node) : _node {node} {
1322 return _node.num_predecessors();
1327 return _node.num_strong_dependencies();
1332 return _node.num_weak_dependencies();
1337 return _node.num_successors();
1342 switch(_node._handle.index()) {
1360 return std::hash<const Node*>{}(&_node);
1364template <
typename V>
1366 for(
size_t i=0; i<_node._num_successors; ++i) {
1367 visitor(TaskView(*_node._edges[i]));
1375template <
typename V>
1377 for(
size_t i=_node._num_successors; i<_node._edges.size(); ++i) {
1378 visitor(TaskView(*_node._edges[i]));
1396 auto operator() (
const tf::Task& task)
const noexcept {
1397 return task.hash_value();
1407struct hash<
tf::TaskView> {
1408 auto operator() (
const tf::TaskView& task_view)
const noexcept {
class to create a graph object
Definition graph.hpp:47
class to create a semophore object for building a concurrency constraint
Definition semaphore.hpp:68
class to define a vector optimized for small array
Definition small_vector.hpp:931
class to access task information from the observer interface
Definition task.hpp:1240
size_t num_predecessors() const
queries the number of predecessors of the task
Definition task.hpp:1321
void for_each_predecessor(V &&visitor) const
applies an visitor callable to each predecessor of the task
Definition task.hpp:1376
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition task.hpp:1365
TaskType type() const
queries the task type
Definition task.hpp:1341
size_t num_weak_dependencies() const
queries the number of weak dependencies of the task
Definition task.hpp:1331
size_t hash_value() const
obtains a hash value of the underlying node
Definition task.hpp:1359
const std::string & name() const
queries the name of the task
Definition task.hpp:1316
size_t num_strong_dependencies() const
queries the number of strong dependencies of the task
Definition task.hpp:1326
size_t num_successors() const
queries the number of successors of the task
Definition task.hpp:1336
class to create a task handle over a taskflow node
Definition task.hpp:263
Task & acquire(Semaphore &semaphore)
makes the task acquire the given semaphore
Definition task.hpp:1024
const std::string & name() const
queries the name of the task
Definition task.hpp:1082
size_t num_strong_dependencies() const
queries the number of strong dependencies of the task
Definition task.hpp:1092
Task & remove_successors(Ts &&... tasks)
removes successor links from this to other tasks
Definition task.hpp:976
size_t num_successors() const
queries the number of successors of the task
Definition task.hpp:1102
size_t hash_value() const
obtains a hash value of the underlying node
Definition task.hpp:1171
void for_each_subflow_task(V &&visitor) const
applies an visitor callable to each subflow task
Definition task.hpp:1162
Task & release(Semaphore &semaphore)
makes the task release the given semaphore
Definition task.hpp:1048
Task & work(C &&callable)
assigns a callable
Definition task.hpp:1185
std::exception_ptr exception_ptr() const
retrieves the exception pointer of this task
Definition task.hpp:1117
void reset()
resets the task handle to null
Definition task.hpp:1072
void for_each_predecessor(V &&visitor) const
applies an visitor callable to each predecessor of the task
Definition task.hpp:1154
void * data() const
queries pointer to user data
Definition task.hpp:1209
void dump(std::ostream &ostream) const
dumps the task through an output stream
Definition task.hpp:1176
Task & succeed(Ts &&... tasks)
adds precedence links from other tasks to this
Definition task.hpp:960
Task & operator=(const Task &other)
replaces the contents with a copy of the other task
Definition task.hpp:996
Task()=default
constructs an empty task
bool empty() const
queries if the task handle is associated with a taskflow node
Definition task.hpp:1107
Task & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition task.hpp:952
bool has_exception_ptr() const
queries if the task has an exception pointer
Definition task.hpp:1122
Task & adopt(tf::Graph &&graph)
creates a module task from a graph by taking over its ownership
Definition task.hpp:990
Task & composed_of(T &object)
creates a module task from a taskflow
Definition task.hpp:984
Task & remove_predecessors(Ts &&... tasks)
removes predecessor links from other tasks to this
Definition task.hpp:968
size_t num_weak_dependencies() const
queries the number of weak dependencies of the task
Definition task.hpp:1097
bool operator==(const Task &rhs) const
compares if two tasks are associated with the same taskflow node
Definition task.hpp:1008
size_t num_predecessors() const
queries the number of predecessors of the task
Definition task.hpp:1087
void reset_work()
resets the associated work to a placeholder
Definition task.hpp:1077
TaskType type() const
returns the task type
Definition task.hpp:1127
bool operator!=(const Task &rhs) const
compares if two tasks are not associated with the same taskflow node
Definition task.hpp:1013
bool has_work() const
queries if the task has a work assigned
Definition task.hpp:1112
Task & data(void *data)
assigns pointer to user data
Definition task.hpp:1214
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition task.hpp:1146
determines if a callable is a condition task
Definition task.hpp:168
determines if a callable is a multi-condition task
Definition task.hpp:188
determines if a callable is a static task
Definition task.hpp:94
determines if a callable is a subflow task
Definition task.hpp:117
taskflow namespace
Definition small_vector.hpp:20
constexpr bool is_condition_task_v
determines if a callable is a condition task (variable template)
Definition task.hpp:179
constexpr bool is_static_task_v
determines if a callable is a static task (variable template)
Definition task.hpp:105
TaskType
enumeration of all task types
Definition task.hpp:21
@ UNDEFINED
undefined task type (for internal use only)
Definition task.hpp:37
@ MODULE
module task type
Definition task.hpp:33
@ SUBFLOW
dynamic (subflow) task type
Definition task.hpp:29
@ CONDITION
condition task type
Definition task.hpp:31
@ ASYNC
asynchronous task type
Definition task.hpp:35
@ PLACEHOLDER
placeholder task type
Definition task.hpp:23
@ RUNTIME
runtime task type
Definition task.hpp:27
@ STATIC
static task type
Definition task.hpp:25
const char * to_string(TaskType type)
convert a task type to a human-readable string
Definition task.hpp:66
constexpr bool is_multi_condition_task_v
determines if a callable is a multi-condition task (variable template)
Definition task.hpp:199
Graph & retrieve_graph(T &target)
retrieves a reference to the underlying tf::Graph from an object
Definition graph.hpp:1098
std::ostream & operator<<(std::ostream &os, const Task &task)
overload of ostream inserter operator for Task
Definition task.hpp:1226
constexpr bool is_subflow_task_v
determines if a callable is a subflow task (variable template)
Definition task.hpp:128
constexpr bool is_runtime_task_v
determines if a callable is a runtime task (variable template)
Definition task.hpp:155
hash specialization for std::hash<tf::Task>