17 PLACEHOLDER_TASK = Node::PLACEHOLDER_WORK,
19 CUDAFLOW_TASK = Node::CUDAFLOW_WORK,
21 STATIC_TASK = Node::STATIC_WORK,
22 DYNAMIC_TASK = Node::DYNAMIC_WORK,
23 CONDITION_TASK = Node::CONDITION_WORK,
24 MODULE_TASK = Node::MODULE_WORK,
31 inline const char* task_type_to_string(TaskType type) {
36 case PLACEHOLDER_TASK: val =
"placeholder";
break;
38 case CUDAFLOW_TASK: val =
"cudaflow";
break;
40 case STATIC_TASK: val =
"static";
break;
41 case DYNAMIC_TASK: val =
"subflow";
break;
42 case CONDITION_TASK: val =
"condition";
break;
43 case MODULE_TASK: val =
"module";
break;
44 default: val =
"undefined";
break;
62 constexpr
bool is_static_task_v = is_invocable_r_v<void, C> &&
63 !is_invocable_r_v<int, C>;
73 constexpr
bool is_dynamic_task_v = is_invocable_r_v<void, C, Subflow&>;
83 constexpr
bool is_condition_task_v = is_invocable_r_v<int, C>;
94 constexpr
bool is_cudaflow_task_v = is_invocable_r_v<void, C, cudaFlow&>;
194 template <
typename C>
195 std::enable_if_t<is_static_task_v<C>,
Task>&
work(C&& callable);
206 template <
typename C>
207 std::enable_if_t<is_dynamic_task_v<C>,
Task>&
work(C&& callable);
218 template <
typename C>
219 std::enable_if_t<is_condition_task_v<C>,
Task>&
work(C&& callable);
221 #ifdef TF_ENABLE_CUDA 231 template <
typename C>
232 std::enable_if_t<is_cudaflow_task_v<C>,
Task>&
work(C&& callable);
253 template <
typename... Ts>
265 template <
typename... Ts>
291 template <
typename V>
297 template <
typename V>
308 TaskType
type()
const;
314 Node* _node {
nullptr};
316 template <
typename T>
319 template <
typename T,
typename... Rest>
320 void _precede(T&&, Rest&&...);
322 template <
typename T>
325 template <
typename T,
typename... Rest>
326 void _succeed(T&&, Rest&&...);
330 inline Task::Task(Node* node) : _node {node} {
338 template <
typename... Ts>
341 _precede(std::forward<Ts>(tasks)...);
347 template <
typename T>
348 void Task::_precede(T&& other) {
349 _node->_precede(other._node);
354 template <
typename T,
typename... Ts>
355 void Task::_precede(T&& task, Ts&&... others) {
356 _precede(std::forward<T>(task));
357 _precede(std::forward<Ts>(others)...);
361 template <
typename... Ts>
364 _succeed(std::forward<Ts>(tasks)...);
370 template <
typename T>
371 void Task::_succeed(T&& other) {
372 other._node->_precede(_node);
377 template <
typename T,
typename... Ts>
378 void Task::_succeed(T&& task, Ts&&... others) {
379 _succeed(std::forward<T>(task));
380 _succeed(std::forward<Ts>(others)...);
385 _node->_handle.emplace<Node::ModuleWork>(&
tf);
403 return _node == rhs._node;
408 return _node != rhs._node;
424 _node->_handle = nstd::monostate{};
434 return _node->num_dependents();
439 return _node->num_strong_dependents();
444 return _node->num_weak_dependents();
449 return _node->num_successors();
454 return _node ==
nullptr;
459 return _node ? _node->_handle.index() != 0 :
false;
464 return static_cast<TaskType
>(_node->_handle.index());
468 template <
typename V>
470 for(
size_t i=0; i<_node->_successors.size(); ++i) {
471 visitor(
Task(_node->_successors[i]));
476 template <
typename V>
478 for(
size_t i=0; i<_node->_dependents.size(); ++i) {
479 visitor(
Task(_node->_dependents[i]));
490 template <
typename C>
492 _node->_handle.emplace<Node::StaticWork>(std::forward<C>(c));
498 template <
typename C>
500 _node->_handle.emplace<Node::DynamicWork>(std::forward<C>(c));
506 template <
typename C>
508 _node->_handle.emplace<Node::ConditionWork>(std::forward<C>(c));
512 #ifdef TF_ENABLE_CUDA 515 template <
typename C>
517 _node->_handle.emplace<Node::cudaFlowWork>(std::forward<C>(c));
613 template <
typename V>
619 template <
typename V>
625 TaskType
type()
const;
631 Node* _node {
nullptr};
671 return _node->num_dependents();
676 return _node->num_strong_dependents();
681 return _node->num_weak_dependents();
686 return _node->num_successors();
696 return _node ==
nullptr;
701 return static_cast<TaskType
>(_node->_handle.index());
706 return _node == rhs._node;
711 return _node != rhs._node;
715 template <
typename V>
717 for(
size_t i=0; i<_node->_successors.size(); ++i) {
718 visitor(
TaskView(_node->_successors[i]));
723 template <
typename V>
725 for(
size_t i=0; i<_node->_dependents.size(); ++i) {
726 visitor(
TaskView(_node->_dependents[i]));
741 struct hash<
tf::Task> {
743 return task.hash_value();
size_t num_dependents() const
queries the number of predecessors of the task
Definition: task.hpp:433
void reset_work()
resets the associated work to a placeholder
Definition: task.hpp:423
void reset()
resets the task handle to null
Definition: task.hpp:418
TaskView()=default
constructs an empty task view
bool operator!=(const TaskView &) const
compares if two taskviews are associated with different tasks
Definition: task.hpp:710
void for_each_dependent(V &&visitor) const
applies an visitor callable to each dependents of the task
Definition: task.hpp:724
TaskType type() const
queries the task type
Definition: task.hpp:700
size_t num_weak_dependents() const
queries the number of weak dependents of the task
Definition: task.hpp:680
Task & composed_of(Taskflow &taskflow)
creates a module task from a taskflow
Definition: task.hpp:384
size_t num_successors() const
queries the number of successors of the task
Definition: task.hpp:685
bool operator==(const Task &rhs) const
compares if two tasks are associated with the same graph node
Definition: task.hpp:402
std::enable_if_t< is_static_task_v< C >, Task > & work(C &&callable)
assigns a static task
Definition: task.hpp:491
Task & succeed(Ts &&... tasks)
adds precedence links from other tasks to this
Definition: task.hpp:362
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition: task.hpp:716
bool operator!=(const Task &rhs) const
compares if two tasks are not associated with the same graph node
Definition: task.hpp:407
bool empty() const
queries if the task view is empty
Definition: task.hpp:695
size_t num_strong_dependents() const
queries the number of strong dependents of the task
Definition: task.hpp:675
Task & operator=(const Task &)
replaces the contents with a copy of the other task
Definition: task.hpp:390
void for_each_dependent(V &&visitor) const
applies an visitor callable to each dependents of the task
Definition: task.hpp:477
main entry to create a task dependency graph
Definition: taskflow.hpp:18
const std::string & name() const
queries the name of the task
Definition: task.hpp:428
class to access task information from the observer interface
Definition: task.hpp:529
bool empty() const
queries if the task handle points to a task node
Definition: task.hpp:453
void reset()
resets to an empty view
Definition: task.hpp:690
size_t num_strong_dependents() const
queries the number of strong dependents of the task
Definition: task.hpp:438
building methods of a task dependency graph
Definition: flow_builder.hpp:13
size_t num_successors() const
queries the number of successors of the task
Definition: task.hpp:448
size_t num_weak_dependents() const
queries the number of weak dependents of the task
Definition: task.hpp:443
handle to a node in a task dependency graph
Definition: task.hpp:113
Task & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition: task.hpp:339
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition: task.hpp:469
Task()=default
constructs an empty task
execution interface for running a taskflow graph
Definition: executor.hpp:43
TaskView & operator=(const TaskView &other)
replaces the contents with a copy of the other task
Definition: task.hpp:647
size_t hash_value() const
obtains a hash value of the underlying node
Definition: task.hpp:484
TaskType type() const
returns the task type
Definition: task.hpp:463
bool operator==(const TaskView &) const
compares if two taskviews are associated with the same task
Definition: task.hpp:705
size_t num_dependents() const
queries the number of predecessors of the task
Definition: task.hpp:670
bool has_work() const
queries if the task has a work assigned
Definition: task.hpp:458
const std::string & name() const
queries the name of the task
Definition: task.hpp:665