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,
25 ASYNC_TASK = Node::ASYNC_WORK,
32 inline const char* task_type_to_string(TaskType type) {
37 case PLACEHOLDER_TASK: val =
"placeholder";
break;
39 case CUDAFLOW_TASK: val =
"cudaflow";
break;
41 case STATIC_TASK: val =
"static";
break;
42 case DYNAMIC_TASK: val =
"subflow";
break;
43 case CONDITION_TASK: val =
"condition";
break;
44 case MODULE_TASK: val =
"module";
break;
45 case ASYNC_TASK: val =
"async";
break;
46 default: val =
"undefined";
break;
64 constexpr
bool is_static_task_v = is_invocable_r_v<void, C> &&
65 !is_invocable_r_v<int, C>;
75 constexpr
bool is_dynamic_task_v = is_invocable_r_v<void, C, Subflow&>;
85 constexpr
bool is_condition_task_v = is_invocable_r_v<int, C>;
96 constexpr
bool is_cudaflow_task_v = is_invocable_r_v<void, C, cudaFlow&>;
196 template <
typename C>
197 std::enable_if_t<is_static_task_v<C>,
Task>&
work(C&& callable);
208 template <
typename C>
209 std::enable_if_t<is_dynamic_task_v<C>,
Task>&
work(C&& callable);
220 template <
typename C>
221 std::enable_if_t<is_condition_task_v<C>,
Task>&
work(C&& callable);
223 #ifdef TF_ENABLE_CUDA 233 template <
typename C>
234 std::enable_if_t<is_cudaflow_task_v<C>,
Task>&
work(C&& callable);
255 template <
typename... Ts>
267 template <
typename... Ts>
293 template <
typename V>
299 template <
typename V>
310 TaskType
type()
const;
316 Node* _node {
nullptr};
318 template <
typename T>
321 template <
typename T,
typename... Rest>
322 void _precede(T&&, Rest&&...);
324 template <
typename T>
327 template <
typename T,
typename... Rest>
328 void _succeed(T&&, Rest&&...);
332 inline Task::Task(Node* node) : _node {node} {
340 template <
typename... Ts>
343 _precede(std::forward<Ts>(tasks)...);
349 template <
typename T>
350 void Task::_precede(T&& other) {
351 _node->_precede(other._node);
356 template <
typename T,
typename... Ts>
357 void Task::_precede(T&& task, Ts&&... others) {
358 _precede(std::forward<T>(task));
359 _precede(std::forward<Ts>(others)...);
363 template <
typename... Ts>
366 _succeed(std::forward<Ts>(tasks)...);
372 template <
typename T>
373 void Task::_succeed(T&& other) {
374 other._node->_precede(_node);
379 template <
typename T,
typename... Ts>
380 void Task::_succeed(T&& task, Ts&&... others) {
381 _succeed(std::forward<T>(task));
382 _succeed(std::forward<Ts>(others)...);
387 _node->_handle.emplace<Node::ModuleWork>(&
tf);
405 return _node == rhs._node;
410 return _node != rhs._node;
426 _node->_handle = nstd::monostate{};
436 return _node->num_dependents();
441 return _node->num_strong_dependents();
446 return _node->num_weak_dependents();
451 return _node->num_successors();
456 return _node ==
nullptr;
461 return _node ? _node->_handle.index() != 0 :
false;
466 return static_cast<TaskType
>(_node->_handle.index());
470 template <
typename V>
472 for(
size_t i=0; i<_node->_successors.size(); ++i) {
473 visitor(
Task(_node->_successors[i]));
478 template <
typename V>
480 for(
size_t i=0; i<_node->_dependents.size(); ++i) {
481 visitor(
Task(_node->_dependents[i]));
492 template <
typename C>
494 _node->_handle.emplace<Node::StaticWork>(std::forward<C>(c));
500 template <
typename C>
502 _node->_handle.emplace<Node::DynamicWork>(std::forward<C>(c));
508 template <
typename C>
510 _node->_handle.emplace<Node::ConditionWork>(std::forward<C>(c));
514 #ifdef TF_ENABLE_CUDA 517 template <
typename C>
519 _node->_handle.emplace<Node::cudaFlowWork>(std::forward<C>(c));
615 template <
typename V>
621 template <
typename V>
627 TaskType
type()
const;
633 Node* _node {
nullptr};
673 return _node->num_dependents();
678 return _node->num_strong_dependents();
683 return _node->num_weak_dependents();
688 return _node->num_successors();
698 return _node ==
nullptr;
703 return static_cast<TaskType
>(_node->_handle.index());
708 return _node == rhs._node;
713 return _node != rhs._node;
717 template <
typename V>
719 for(
size_t i=0; i<_node->_successors.size(); ++i) {
720 visitor(
TaskView(_node->_successors[i]));
725 template <
typename V>
727 for(
size_t i=0; i<_node->_dependents.size(); ++i) {
728 visitor(
TaskView(_node->_dependents[i]));
743 struct hash<
tf::Task> {
745 return task.hash_value();
size_t num_dependents() const
queries the number of predecessors of the task
Definition: task.hpp:435
void reset_work()
resets the associated work to a placeholder
Definition: task.hpp:425
void reset()
resets the task handle to null
Definition: task.hpp:420
TaskView()=default
constructs an empty task view
bool operator!=(const TaskView &) const
compares if two taskviews are associated with different tasks
Definition: task.hpp:712
void for_each_dependent(V &&visitor) const
applies an visitor callable to each dependents of the task
Definition: task.hpp:726
TaskType type() const
queries the task type
Definition: task.hpp:702
size_t num_weak_dependents() const
queries the number of weak dependents of the task
Definition: task.hpp:682
Task & composed_of(Taskflow &taskflow)
creates a module task from a taskflow
Definition: task.hpp:386
size_t num_successors() const
queries the number of successors of the task
Definition: task.hpp:687
bool operator==(const Task &rhs) const
compares if two tasks are associated with the same graph node
Definition: task.hpp:404
std::enable_if_t< is_static_task_v< C >, Task > & work(C &&callable)
assigns a static task
Definition: task.hpp:493
Task & succeed(Ts &&... tasks)
adds precedence links from other tasks to this
Definition: task.hpp:364
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition: task.hpp:718
bool operator!=(const Task &rhs) const
compares if two tasks are not associated with the same graph node
Definition: task.hpp:409
bool empty() const
queries if the task view is empty
Definition: task.hpp:697
size_t num_strong_dependents() const
queries the number of strong dependents of the task
Definition: task.hpp:677
Task & operator=(const Task &)
replaces the contents with a copy of the other task
Definition: task.hpp:392
void for_each_dependent(V &&visitor) const
applies an visitor callable to each dependents of the task
Definition: task.hpp:479
main entry to create a task dependency graph
Definition: core/taskflow.hpp:18
const std::string & name() const
queries the name of the task
Definition: task.hpp:430
class to access task information from the observer interface
Definition: task.hpp:531
bool empty() const
queries if the task handle points to a task node
Definition: task.hpp:455
void reset()
resets to an empty view
Definition: task.hpp:692
size_t num_strong_dependents() const
queries the number of strong dependents of the task
Definition: task.hpp:440
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:450
size_t num_weak_dependents() const
queries the number of weak dependents of the task
Definition: task.hpp:445
handle to a node in a task dependency graph
Definition: task.hpp:115
Task & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition: task.hpp:341
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition: task.hpp:471
Task()=default
constructs an empty task
execution interface for running a taskflow graph
Definition: executor.hpp:24
TaskView & operator=(const TaskView &other)
replaces the contents with a copy of the other task
Definition: task.hpp:649
size_t hash_value() const
obtains a hash value of the underlying node
Definition: task.hpp:486
TaskType type() const
returns the task type
Definition: task.hpp:465
bool operator==(const TaskView &) const
compares if two taskviews are associated with the same task
Definition: task.hpp:707
size_t num_dependents() const
queries the number of predecessors of the task
Definition: task.hpp:672
bool has_work() const
queries if the task has a work assigned
Definition: task.hpp:460
const std::string & name() const
queries the name of the task
Definition: task.hpp:667