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 <HasGraph T>
541 template <
typename... Ts>
563 template <
typename... Ts>
593 template <
typename... Ts>
623 template <
typename... Ts>
640 template <
typename I>
657 template <
typename I>
763 template <
typename V>
787 template <
typename V>
810 template <
typename V>
850 void dump(std::ostream& ostream)
const;
934 Node* _node {
nullptr};
946template <
typename... Ts>
948 (_node->_precede(tasks._node), ...);
954template <
typename... Ts>
956 (tasks._node->_precede(_node), ...);
962template <
typename... Ts>
964 (tasks._node->_remove_successors(_node), ...);
965 (_node->_remove_predecessors(tasks._node), ...);
970template <
typename... Ts>
972 (_node->_remove_successors(tasks._node), ...);
973 (tasks._node->_remove_predecessors(_node), ...);
986 _node->_handle.emplace<Node::AdoptedModule>(std::move(graph));
1004 return _node == rhs._node;
1009 return _node != rhs._node;
1014 _node->_name =
name;
1020 if(!_node->_semaphores) {
1021 _node->_semaphores = std::make_unique<Node::Semaphores>();
1023 _node->_semaphores->to_acquire.push_back(&s);
1028template <
typename I>
1030 if(!_node->_semaphores) {
1031 _node->_semaphores = std::make_unique<Node::Semaphores>();
1033 _node->_semaphores->to_acquire.reserve(
1034 _node->_semaphores->to_acquire.size() + std::distance(first, last)
1036 for(
auto s = first; s != last; ++s){
1037 _node->_semaphores->to_acquire.push_back(&(*s));
1044 if(!_node->_semaphores) {
1045 _node->_semaphores = std::make_unique<Node::Semaphores>();
1047 _node->_semaphores->to_release.push_back(&s);
1052template <
typename I>
1054 if(!_node->_semaphores) {
1055 _node->_semaphores = std::make_unique<Node::Semaphores>();
1057 _node->_semaphores->to_release.reserve(
1058 _node->_semaphores->to_release.size() + std::distance(first, last)
1060 for(
auto s = first; s != last; ++s) {
1061 _node->_semaphores->to_release.push_back(&(*s));
1073 _node->_handle.emplace<std::monostate>();
1078 return _node->_name;
1088 return _node->num_strong_dependencies();
1093 return _node->num_weak_dependencies();
1098 return _node->num_successors();
1103 return _node ==
nullptr;
1108 return _node ? _node->_handle.index() != 0 :
false;
1113 return _node ? _node->_exception_ptr :
nullptr;
1118 return _node ? (_node->_exception_ptr !=
nullptr) :
false;
1123 switch(_node->_handle.index()) {
1140template <
typename V>
1142 for(
size_t i=0; i<_node->_num_successors; ++i) {
1143 visitor(
Task(_node->_edges[i]));
1148template <
typename V>
1150 for(
size_t i=_node->_num_successors; i<_node->_edges.size(); ++i) {
1151 visitor(
Task(_node->_edges[i]));
1156template <
typename V>
1158 if(
auto ptr = std::get_if<Node::Subflow>(&_node->_handle); ptr) {
1159 for(
auto itr = ptr->subgraph.begin(); itr != ptr->subgraph.end(); ++itr) {
1160 visitor(
Task(*itr));
1167 return std::hash<Node*>{}(_node);
1179template <
typename C>
1183 _node->_handle.emplace<Node::Static>(std::forward<C>(c));
1186 _node->_handle.emplace<Node::Runtime>(std::forward<C>(c));
1189 _node->_handle.emplace<Node::Subflow>(std::forward<C>(c));
1192 _node->_handle.emplace<Node::Condition>(std::forward<C>(c));
1195 _node->_handle.emplace<Node::MultiCondition>(std::forward<C>(c));
1198 static_assert(dependent_false_v<C>,
"invalid task callable");
1205 return _node->_data;
1210 _node->_data =
data;
1237 friend class Executor;
1244 const std::string&
name()
const;
1274 template <
typename V>
1285 template <
typename V>
1300 TaskView(
const Node&);
1301 TaskView(
const TaskView&) =
default;
1307inline TaskView::TaskView(
const Node& node) : _node {node} {
1317 return _node.num_predecessors();
1322 return _node.num_strong_dependencies();
1327 return _node.num_weak_dependencies();
1332 return _node.num_successors();
1337 switch(_node._handle.index()) {
1355 return std::hash<const Node*>{}(&_node);
1359template <
typename V>
1361 for(
size_t i=0; i<_node._num_successors; ++i) {
1362 visitor(TaskView(*_node._edges[i]));
1370template <
typename V>
1372 for(
size_t i=_node._num_successors; i<_node._edges.size(); ++i) {
1373 visitor(TaskView(*_node._edges[i]));
1391 auto operator() (
const tf::Task& task)
const noexcept {
1392 return task.hash_value();
1402struct hash<
tf::TaskView> {
1403 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:1235
size_t num_predecessors() const
queries the number of predecessors of the task
Definition task.hpp:1316
void for_each_predecessor(V &&visitor) const
applies an visitor callable to each predecessor of the task
Definition task.hpp:1371
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition task.hpp:1360
TaskType type() const
queries the task type
Definition task.hpp:1336
size_t num_weak_dependencies() const
queries the number of weak dependencies of the task
Definition task.hpp:1326
size_t hash_value() const
obtains a hash value of the underlying node
Definition task.hpp:1354
const std::string & name() const
queries the name of the task
Definition task.hpp:1311
size_t num_strong_dependencies() const
queries the number of strong dependencies of the task
Definition task.hpp:1321
size_t num_successors() const
queries the number of successors of the task
Definition task.hpp:1331
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:1019
const std::string & name() const
queries the name of the task
Definition task.hpp:1077
size_t num_strong_dependencies() const
queries the number of strong dependencies of the task
Definition task.hpp:1087
Task & remove_successors(Ts &&... tasks)
removes successor links from this to other tasks
Definition task.hpp:971
size_t num_successors() const
queries the number of successors of the task
Definition task.hpp:1097
size_t hash_value() const
obtains a hash value of the underlying node
Definition task.hpp:1166
void for_each_subflow_task(V &&visitor) const
applies an visitor callable to each subflow task
Definition task.hpp:1157
Task & release(Semaphore &semaphore)
makes the task release the given semaphore
Definition task.hpp:1043
Task & work(C &&callable)
assigns a callable
Definition task.hpp:1180
std::exception_ptr exception_ptr() const
retrieves the exception pointer of this task
Definition task.hpp:1112
void reset()
resets the task handle to null
Definition task.hpp:1067
void for_each_predecessor(V &&visitor) const
applies an visitor callable to each predecessor of the task
Definition task.hpp:1149
void * data() const
queries pointer to user data
Definition task.hpp:1204
void dump(std::ostream &ostream) const
dumps the task through an output stream
Definition task.hpp:1171
Task & succeed(Ts &&... tasks)
adds precedence links from other tasks to this
Definition task.hpp:955
Task & operator=(const Task &other)
replaces the contents with a copy of the other task
Definition task.hpp:991
Task()=default
constructs an empty task
bool empty() const
queries if the task handle is associated with a taskflow node
Definition task.hpp:1102
Task & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition task.hpp:947
bool has_exception_ptr() const
queries if the task has an exception pointer
Definition task.hpp:1117
Task & adopt(tf::Graph &&graph)
creates an adopted module task from the given graph with move semantics
Definition task.hpp:985
Task & composed_of(T &object)
creates a module task from a taskflow
Definition task.hpp:979
Task & remove_predecessors(Ts &&... tasks)
removes predecessor links from other tasks to this
Definition task.hpp:963
size_t num_weak_dependencies() const
queries the number of weak dependencies of the task
Definition task.hpp:1092
bool operator==(const Task &rhs) const
compares if two tasks are associated with the same taskflow node
Definition task.hpp:1003
size_t num_predecessors() const
queries the number of predecessors of the task
Definition task.hpp:1082
void reset_work()
resets the associated work to a placeholder
Definition task.hpp:1072
TaskType type() const
returns the task type
Definition task.hpp:1122
bool operator!=(const Task &rhs) const
compares if two tasks are not associated with the same taskflow node
Definition task.hpp:1008
bool has_work() const
queries if the task has a work assigned
Definition task.hpp:1107
Task & data(void *data)
assigns pointer to user data
Definition task.hpp:1209
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition task.hpp:1141
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
Graph & retrieve_graph(T &t)
retrieves a reference to the underlying tf::Graph from an object
Definition graph.hpp:975
constexpr bool is_multi_condition_task_v
determines if a callable is a multi-condition task (variable template)
Definition task.hpp:199
std::ostream & operator<<(std::ostream &os, const Task &task)
overload of ostream inserter operator for Task
Definition task.hpp:1221
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>