44inline constexpr std::array<TaskType, 7> TASK_TYPES = {
78 default: val =
"undefined";
break;
141 std::same_as<std::invoke_result_t<C>,
void>;
221 std::same_as<std::invoke_result_t<C, tf::Subflow&>,
void>;
304 (std::invocable<C, tf::Runtime&> &&
305 std::same_as<std::invoke_result_t<C, tf::Runtime&>,
void>) ||
306 (std::invocable<C, tf::NonpreemptiveRuntime&> &&
307 std::same_as<std::invoke_result_t<C, tf::NonpreemptiveRuntime&>,
void>);
398 std::convertible_to<std::invoke_result_t<C>,
int>;
571 friend class FlowBuilder;
572 friend class Runtime;
573 friend class NonpreemptiveRuntime;
574 friend class Taskflow;
575 friend class TaskView;
576 friend class Executor;
663 const std::string&
name()
const;
787 template <
typename C>
807 template <GraphLike T>
852 template <
typename... Ts>
874 template <
typename... Ts>
904 template <
typename... Ts>
934 template <
typename... Ts>
951 template <
typename I>
968 template <
typename I>
1074 template <
typename V>
1098 template <
typename V>
1121 template <
typename V>
1161 void dump(std::ostream& ostream)
const;
1245 Node* _node {
nullptr};
1249inline Task::Task(Node* node) : _node {node} {
1257template <
typename... Ts>
1259 (_node->_precede(tasks._node), ...);
1265template <
typename... Ts>
1267 (tasks._node->_precede(_node), ...);
1273template <
typename... Ts>
1275 (tasks._node->_remove_successors(_node), ...);
1276 (_node->_remove_predecessors(tasks._node), ...);
1281template <
typename... Ts>
1283 (_node->_remove_successors(tasks._node), ...);
1284 (tasks._node->_remove_predecessors(_node), ...);
1289template <GraphLike T>
1297 _node->_handle.emplace<Node::AdoptedModule>(std::move(graph));
1315 return _node == rhs._node;
1320 return _node != rhs._node;
1325 _node->_name =
name;
1331 if(!_node->_semaphores) {
1332 _node->_semaphores = std::make_unique<Node::Semaphores>();
1334 _node->_semaphores->to_acquire.push_back(&s);
1339template <
typename I>
1341 if(!_node->_semaphores) {
1342 _node->_semaphores = std::make_unique<Node::Semaphores>();
1344 _node->_semaphores->to_acquire.reserve(
1345 _node->_semaphores->to_acquire.size() + std::distance(first, last)
1347 for(
auto s = first; s != last; ++s){
1348 _node->_semaphores->to_acquire.push_back(&(*s));
1355 if(!_node->_semaphores) {
1356 _node->_semaphores = std::make_unique<Node::Semaphores>();
1358 _node->_semaphores->to_release.push_back(&s);
1363template <
typename I>
1365 if(!_node->_semaphores) {
1366 _node->_semaphores = std::make_unique<Node::Semaphores>();
1368 _node->_semaphores->to_release.reserve(
1369 _node->_semaphores->to_release.size() + std::distance(first, last)
1371 for(
auto s = first; s != last; ++s) {
1372 _node->_semaphores->to_release.push_back(&(*s));
1384 _node->_handle.emplace<std::monostate>();
1389 return _node->_name;
1399 return _node->num_strong_dependencies();
1404 return _node->num_weak_dependencies();
1409 return _node->num_successors();
1414 return _node ==
nullptr;
1419 return _node ? _node->_handle.index() != 0 :
false;
1424 return _node ? _node->_exception_ptr :
nullptr;
1429 return _node ? (_node->_exception_ptr !=
nullptr) :
false;
1434 switch(_node->_handle.index()) {
1451template <
typename V>
1453 for(
size_t i=0; i<_node->_num_successors; ++i) {
1454 visitor(
Task(_node->_edges[i]));
1459template <
typename V>
1461 for(
size_t i=_node->_num_successors; i<_node->_edges.size(); ++i) {
1462 visitor(
Task(_node->_edges[i]));
1467template <
typename V>
1469 if(
auto ptr = std::get_if<Node::Subflow>(&_node->_handle); ptr) {
1470 for(
auto itr = ptr->subgraph.begin(); itr != ptr->subgraph.end(); ++itr) {
1471 visitor(
Task(*itr));
1478 return std::hash<Node*>{}(_node);
1490template <
typename C>
1494 _node->_handle.emplace<Node::Static>(std::forward<C>(c));
1497 _node->_handle.emplace<Node::Runtime>(std::forward<C>(c));
1500 _node->_handle.emplace<Node::Subflow>(std::forward<C>(c));
1503 _node->_handle.emplace<Node::Condition>(std::forward<C>(c));
1506 _node->_handle.emplace<Node::MultiCondition>(std::forward<C>(c));
1509 static_assert(dependent_false_v<C>,
"invalid task callable");
1516 return _node->_data;
1521 _node->_data =
data;
1548 friend class Executor;
1555 const std::string&
name()
const;
1585 template <
typename V>
1596 template <
typename V>
1611 TaskView(
const Node&);
1612 TaskView(
const TaskView&) =
default;
1618inline TaskView::TaskView(
const Node& node) : _node {node} {
1628 return _node.num_predecessors();
1633 return _node.num_strong_dependencies();
1638 return _node.num_weak_dependencies();
1643 return _node.num_successors();
1648 switch(_node._handle.index()) {
1666 return std::hash<const Node*>{}(&_node);
1670template <
typename V>
1672 for(
size_t i=0; i<_node._num_successors; ++i) {
1673 visitor(TaskView(*_node._edges[i]));
1681template <
typename V>
1683 for(
size_t i=_node._num_successors; i<_node._edges.size(); ++i) {
1684 visitor(TaskView(*_node._edges[i]));
1747 auto operator() (
const tf::Task& task)
const noexcept {
1748 return task.hash_value();
1808struct hash<
tf::TaskView> {
1809 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:1546
size_t num_predecessors() const
queries the number of predecessors of the task
Definition task.hpp:1627
void for_each_predecessor(V &&visitor) const
applies an visitor callable to each predecessor of the task
Definition task.hpp:1682
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition task.hpp:1671
TaskType type() const
queries the task type
Definition task.hpp:1647
size_t num_weak_dependencies() const
queries the number of weak dependencies of the task
Definition task.hpp:1637
size_t hash_value() const
obtains a hash value of the underlying node
Definition task.hpp:1665
const std::string & name() const
queries the name of the task
Definition task.hpp:1622
size_t num_strong_dependencies() const
queries the number of strong dependencies of the task
Definition task.hpp:1632
size_t num_successors() const
queries the number of successors of the task
Definition task.hpp:1642
class to create a task handle over a taskflow node
Definition task.hpp:569
Task & acquire(Semaphore &semaphore)
makes the task acquire the given semaphore
Definition task.hpp:1330
const std::string & name() const
queries the name of the task
Definition task.hpp:1388
size_t num_strong_dependencies() const
queries the number of strong dependencies of the task
Definition task.hpp:1398
Task & remove_successors(Ts &&... tasks)
removes successor links from this to other tasks
Definition task.hpp:1282
size_t num_successors() const
queries the number of successors of the task
Definition task.hpp:1408
size_t hash_value() const
obtains a hash value of the underlying node
Definition task.hpp:1477
void for_each_subflow_task(V &&visitor) const
applies an visitor callable to each subflow task
Definition task.hpp:1468
Task & release(Semaphore &semaphore)
makes the task release the given semaphore
Definition task.hpp:1354
Task & work(C &&callable)
assigns a callable
Definition task.hpp:1491
std::exception_ptr exception_ptr() const
retrieves the exception pointer of this task
Definition task.hpp:1423
void reset()
resets the task handle to null
Definition task.hpp:1378
void for_each_predecessor(V &&visitor) const
applies an visitor callable to each predecessor of the task
Definition task.hpp:1460
void * data() const
queries pointer to user data
Definition task.hpp:1515
void dump(std::ostream &ostream) const
dumps the task through an output stream
Definition task.hpp:1482
Task & succeed(Ts &&... tasks)
adds precedence links from other tasks to this
Definition task.hpp:1266
Task & operator=(const Task &other)
replaces the contents with a copy of the other task
Definition task.hpp:1302
Task()=default
constructs an empty task
bool empty() const
queries if the task handle is associated with a taskflow node
Definition task.hpp:1413
Task & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition task.hpp:1258
bool has_exception_ptr() const
queries if the task has an exception pointer
Definition task.hpp:1428
Task & adopt(tf::Graph &&graph)
creates a module task from a graph by taking over its ownership
Definition task.hpp:1296
Task & composed_of(T &object)
creates a module task from a taskflow
Definition task.hpp:1290
Task & remove_predecessors(Ts &&... tasks)
removes predecessor links from other tasks to this
Definition task.hpp:1274
size_t num_weak_dependencies() const
queries the number of weak dependencies of the task
Definition task.hpp:1403
bool operator==(const Task &rhs) const
compares if two tasks are associated with the same taskflow node
Definition task.hpp:1314
size_t num_predecessors() const
queries the number of predecessors of the task
Definition task.hpp:1393
void reset_work()
resets the associated work to a placeholder
Definition task.hpp:1383
TaskType type() const
returns the task type
Definition task.hpp:1433
bool operator!=(const Task &rhs) const
compares if two tasks are not associated with the same taskflow node
Definition task.hpp:1319
bool has_work() const
queries if the task has a work assigned
Definition task.hpp:1418
Task & data(void *data)
assigns pointer to user data
Definition task.hpp:1520
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition task.hpp:1452
determines if a callable is a condition task
Definition task.hpp:397
determines if a callable is a multi-condition task
Definition task.hpp:494
determines if a callable is a static task
Definition task.hpp:140
determines if a callable is a subflow task
Definition task.hpp:220
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:408
constexpr bool is_static_task_v
determines if a callable is a static task (variable template)
Definition task.hpp:151
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:505
Graph & retrieve_graph(T &target)
retrieves a reference to the underlying tf::Graph from an object
Definition graph.hpp:1067
std::ostream & operator<<(std::ostream &os, const Task &task)
overload of ostream inserter operator for Task
Definition task.hpp:1532
constexpr bool is_subflow_task_v
determines if a callable is a subflow task (variable template)
Definition task.hpp:231
constexpr bool is_runtime_task_v
determines if a callable is a runtime task (variable template)
Definition task.hpp:317
hash specialization for std::hash<tf::Task>