19 constexpr
bool is_static_task_v = is_invocable_r_v<void, C> &&
20 !is_invocable_r_v<int, C>;
30 constexpr
bool is_dynamic_task_v = is_invocable_r_v<void, C, Subflow&>;
40 constexpr
bool is_condition_task_v = is_invocable_r_v<int, C>;
51 constexpr
bool is_cudaflow_task_v = is_invocable_r_v<void, C, cudaFlow&>;
149 template <
typename C>
150 std::enable_if_t<is_static_task_v<C>,
Task>&
work(C&& callable);
161 template <
typename C>
162 std::enable_if_t<is_dynamic_task_v<C>,
Task>&
work(C&& callable);
173 template <
typename C>
174 std::enable_if_t<is_condition_task_v<C>,
Task>&
work(C&& callable);
176 #ifdef TF_ENABLE_CUDA 186 template <
typename C>
187 std::enable_if_t<is_cudaflow_task_v<C>,
Task>&
work(C&& callable);
208 template <
typename... Ts>
220 template <
typename... Ts>
246 template <
typename V>
252 template <
typename V>
265 Node* _node {
nullptr};
267 template <
typename T>
270 template <
typename T,
typename... Rest>
271 void _precede(T&&, Rest&&...);
273 template <
typename T>
276 template <
typename T,
typename... Rest>
277 void _succeed(T&&, Rest&&...);
281 inline Task::Task(Node* node) : _node {node} {
289 template <
typename... Ts>
292 _precede(std::forward<Ts>(tasks)...);
298 template <
typename T>
299 void Task::_precede(T&& other) {
300 _node->_precede(other._node);
305 template <
typename T,
typename... Ts>
306 void Task::_precede(T&& task, Ts&&... others) {
307 _precede(std::forward<T>(task));
308 _precede(std::forward<Ts>(others)...);
312 template <
typename... Ts>
315 _succeed(std::forward<Ts>(tasks)...);
321 template <
typename T>
322 void Task::_succeed(T&& other) {
323 other._node->_precede(_node);
328 template <
typename T,
typename... Ts>
329 void Task::_succeed(T&& task, Ts&&... others) {
330 _succeed(std::forward<T>(task));
331 _succeed(std::forward<Ts>(others)...);
336 _node->_handle.emplace<Node::ModuleWork>(&
tf);
354 return _node == rhs._node;
359 return _node != rhs._node;
375 _node->_handle = nstd::monostate{};
385 return _node->num_dependents();
390 return _node->num_strong_dependents();
395 return _node->num_weak_dependents();
400 return _node->num_successors();
405 return _node ==
nullptr;
410 return _node ? _node->_handle.index() != 0 :
false;
414 template <
typename V>
416 for(
size_t i=0; i<_node->_successors.size(); ++i) {
417 visitor(
Task(_node->_successors[i]));
422 template <
typename V>
424 for(
size_t i=0; i<_node->_dependents.size(); ++i) {
425 visitor(
Task(_node->_dependents[i]));
436 template <
typename C>
438 _node->_handle.emplace<Node::StaticWork>(std::forward<C>(c));
444 template <
typename C>
446 _node->_handle.emplace<Node::DynamicWork>(std::forward<C>(c));
452 template <
typename C>
454 _node->_handle.emplace<Node::ConditionWork>(std::forward<C>(c));
458 #ifdef TF_ENABLE_CUDA 461 template <
typename C>
463 _node->_handle.emplace<Node::cudaFlowWork>(std::forward<C>(c));
559 template <
typename V>
565 template <
typename V>
572 Node* _node {
nullptr};
612 return _node->num_dependents();
617 return _node->num_strong_dependents();
622 return _node->num_weak_dependents();
627 return _node->num_successors();
637 return _node ==
nullptr;
642 return _node == rhs._node;
647 return _node != rhs._node;
651 template <
typename V>
653 for(
size_t i=0; i<_node->_successors.size(); ++i) {
654 visitor(
TaskView(_node->_successors[i]));
659 template <
typename V>
661 for(
size_t i=0; i<_node->_dependents.size(); ++i) {
662 visitor(
TaskView(_node->_dependents[i]));
677 struct hash<
tf::Task> {
679 return task.hash_value();
size_t num_dependents() const
queries the number of predecessors of the task
Definition: task.hpp:384
void reset_work()
resets the associated work to a placeholder
Definition: task.hpp:374
void reset()
resets the task handle to null
Definition: task.hpp:369
TaskView()=default
constructs an empty task view
bool operator!=(const TaskView &) const
compares if two taskviews are associated with different tasks
Definition: task.hpp:646
void for_each_dependent(V &&visitor) const
applies an visitor callable to each dependents of the task
Definition: task.hpp:660
size_t num_weak_dependents() const
queries the number of weak dependents of the task
Definition: task.hpp:621
Task & composed_of(Taskflow &taskflow)
creates a module task from a taskflow
Definition: task.hpp:335
size_t num_successors() const
queries the number of successors of the task
Definition: task.hpp:626
bool operator==(const Task &rhs) const
compares if two tasks are associated with the same graph node
Definition: task.hpp:353
std::enable_if_t< is_static_task_v< C >, Task > & work(C &&callable)
assigns a static task
Definition: task.hpp:437
Task & succeed(Ts &&... tasks)
adds precedence links from other tasks to this
Definition: task.hpp:313
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition: task.hpp:652
bool operator!=(const Task &rhs) const
compares if two tasks are not associated with the same graph node
Definition: task.hpp:358
bool empty() const
queries if the task view is empty
Definition: task.hpp:636
size_t num_strong_dependents() const
queries the number of strong dependents of the task
Definition: task.hpp:616
Task & operator=(const Task &)
replaces the contents with a copy of the other task
Definition: task.hpp:341
void for_each_dependent(V &&visitor) const
applies an visitor callable to each dependents of the task
Definition: task.hpp:423
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:379
immutable accessor class to a task node used by tf::ExecutorObserver
Definition: task.hpp:475
bool empty() const
queries if the task handle points to a task node
Definition: task.hpp:404
void reset()
resets to an empty view
Definition: task.hpp:631
size_t num_strong_dependents() const
queries the number of strong dependents of the task
Definition: task.hpp:389
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:399
size_t num_weak_dependents() const
queries the number of weak dependents of the task
Definition: task.hpp:394
handle to a node in a task dependency graph
Definition: task.hpp:68
Task & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition: task.hpp:290
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition: task.hpp:415
Task()=default
constructs an empty task
execution interface for running a taskflow graph
Definition: executor.hpp:32
TaskView & operator=(const TaskView &other)
replaces the contents with a copy of the other task
Definition: task.hpp:588
size_t hash_value() const
obtains a hash value of the underlying node
Definition: task.hpp:430
bool operator==(const TaskView &) const
compares if two taskviews are associated with the same task
Definition: task.hpp:641
size_t num_dependents() const
queries the number of predecessors of the task
Definition: task.hpp:611
bool has_work() const
queries if the task has a work assigned
Definition: task.hpp:409
const std::string & name() const
queries the name of the task
Definition: task.hpp:606