4#include "../algorithm/partitioner.hpp"
24 friend class Executor;
51 template <StaticTask C>
72 template <RuntimeTask C>
97 template <SubflowTask C>
130 template <ConditionTask C>
164 template <MultiConditionTask C>
191 template <
typename... C>
requires (
sizeof...(C) > 1)
192 auto emplace(C&&... callables);
268 template <HasGraph T>
333 void linearize(std::vector<Task>& tasks);
350 void linearize(std::initializer_list<Task> tasks);
389 template <
typename B,
typename E,
typename C,
typename P = DefaultPartitioner>
431 template <
typename B,
typename E,
typename S,
typename C,
typename P = DefaultPartitioner>
470 template <
typename R,
typename C,
typename P = DefaultPartitioner>
511 template <
typename B,
typename E,
typename O,
typename C,
552 template <
typename B1,
typename E1,
typename B2,
typename O,
typename C,
555 Task transform(B1 first1, E1 last1, B2 first2, O d_first, C c, P part = P());
594 template <
typename B,
typename E,
typename T,
typename O,
typename P = DefaultPartitioner>
651 template <
typename R,
typename T,
typename L,
typename G,
typename P = DefaultPartitioner>
693 template <
typename B,
typename E,
typename T,
typename BOP,
typename UOP,
735 template <
typename B1,
typename E1,
typename B2,
typename T,
739 B1 first1, E1 last1, B2 first2, T& init, BOP_R bop_r, BOP_T bop_t, P part = P()
784 template <
typename B,
typename E,
typename D,
typename BOP>
828 template <
typename B,
typename E,
typename D,
typename BOP,
typename T>
871 template <
typename B,
typename E,
typename D,
typename T,
typename BOP>
919 template <
typename B,
typename E,
typename D,
typename BOP,
typename UOP>
966 template <
typename B,
typename E,
typename D,
typename BOP,
typename UOP,
typename T>
1012 template <
typename B,
typename E,
typename D,
typename T,
typename BOP,
typename UOP>
1064 template <
typename B,
typename E,
typename T,
typename UOP,
typename P = DefaultPartitioner>
1065 Task find_if(B first, E last, T &result, UOP predicate, P part = P());
1112 template <
typename B,
typename E,
typename T,
typename UOP,
typename P = DefaultPartitioner>
1164 template <
typename B,
typename E,
typename T,
typename C,
typename P>
1216 template <
typename B,
typename E,
typename T,
typename C,
typename P>
1242 template <
typename B,
typename E,
typename C>
1264 template <
typename B,
typename E>
1293 template <
typename B1,
typename E1,
typename B2,
typename E2,
1296 Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first, P part = P());
1327 template <
typename B1,
typename E1,
typename B2,
typename E2,
1330 Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first, C cmp, P part = P());
1341 template <
typename L>
1342 void _linearize(L&);
1351template <StaticTask C>
1354 std::in_place_type_t<Node::Static>{}, std::forward<C>(c)
1359template <RuntimeTask C>
1361 if constexpr (std::is_invocable_v<C, tf::Runtime&>) {
1363 std::in_place_type_t<Node::Runtime>{}, std::forward<C>(c)
1366 else if constexpr (std::is_invocable_v<C, tf::NonpreemptiveRuntime&>) {
1367 return Task(
_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1368 std::in_place_type_t<Node::NonpreemptiveRuntime>{}, std::forward<C>(c)
1372 static_assert(dependent_false_v<C>,
"invalid runtime task callable");
1377template <SubflowTask C>
1379 return Task(
_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1380 std::in_place_type_t<Node::Subflow>{}, std::forward<C>(c)
1385template <ConditionTask C>
1387 return Task(
_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1388 std::in_place_type_t<Node::Condition>{}, std::forward<C>(c)
1393template <MultiConditionTask C>
1395 return Task(
_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1396 std::in_place_type_t<Node::MultiCondition>{}, std::forward<C>(c)
1401template <HasGraph T>
1411 std::in_place_type_t<Node::AdoptedModule>{}, std::move(graph)
1418 std::in_place_type_t<Node::Placeholder>{}
1424template <
typename... C>
requires (
sizeof...(C) > 1)
1426 return std::make_tuple(
emplace(std::forward<C>(cs))...);
1437 for(
size_t i=0; i<task._node->_num_successors; ++i) {
1438 task._node->_edges[i]->_remove_predecessors(task._node);
1442 for(
size_t i=task._node->_num_successors; i<task._node->_edges.size(); ++i) {
1443 task._node->_edges[i]->_remove_successors(task._node);
1446 _graph._erase(task._node);
1451template <
typename L>
1452void FlowBuilder::_linearize(L& keys) {
1454 auto itr = keys.begin();
1455 auto end = keys.end();
1463 for(++nxt; nxt != end; ++nxt, ++itr) {
1464 itr->_node->_precede(nxt->_node);
1516class Subflow :
public FlowBuilder {
1518 friend class Executor;
1519 friend class FlowBuilder;
1576 void retain(
bool flag)
noexcept;
1601inline Subflow::Subflow(Executor& executor, Worker& worker, Node* node, Graph& graph) :
1602 FlowBuilder {graph},
1603 _executor {executor},
1608 _node->_nstate &= ~(NSTATE::JOINED_SUBFLOW | NSTATE::RETAIN_SUBFLOW);
1616 return !(_node->_nstate & NSTATE::JOINED_SUBFLOW);
1628 _node->_nstate |= NSTATE::RETAIN_SUBFLOW;
1631 _node->_nstate &= ~NSTATE::RETAIN_SUBFLOW;
1640 return _node->_nstate & NSTATE::RETAIN_SUBFLOW;
class to create an empty task parameter for compile-time optimization
Definition graph.hpp:166
class to create an executor
Definition executor.hpp:62
Task inclusive_scan(B first, E last, D d_first, BOP bop, T init)
creates an STL-styled parallel inclusive-scan task with an initial value
Task inclusive_scan(B first, E last, D d_first, BOP bop)
creates an STL-styled parallel inclusive-scan task
Task for_each_by_index(R range, C callable, P part=P())
constructs an index range-based parallel-for task
Task sort(B first, E last, C cmp)
constructs a dynamic task to perform STL-styled parallel sort
Task adopt(Graph &&graph)
creates an adopted module task from the given graph with move semantics
Definition flow_builder.hpp:1409
Task for_each_index(B first, E last, S step, C callable, P part=P())
constructs an index-based parallel-for task
Task reduce_by_index(R range, T &init, L lop, G gop, P part=P())
constructs an index range-based parallel-reduction task
Task find_if(B first, E last, T &result, UOP predicate, P part=P())
constructs a task to perform STL-styled find-if algorithm
Task transform_inclusive_scan(B first, E last, D d_first, BOP bop, UOP uop, T init)
creates an STL-styled parallel transform-inclusive scan task
Task emplace(C &&callable)
creates a static task
Definition flow_builder.hpp:1352
Task exclusive_scan(B first, E last, D d_first, T init, BOP bop)
creates an STL-styled parallel exclusive-scan task
void erase(Task task)
removes a task from a taskflow
Definition flow_builder.hpp:1430
Task transform_reduce(B first, E last, T &init, BOP bop, UOP uop, P part=P())
constructs an STL-styled parallel transform-reduce task
Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first, P part=P())
merges two sorted ranges into a single sorted output using the std::less comparator
FlowBuilder(Graph &graph)
constructs a flow builder with a graph
Definition flow_builder.hpp:1346
Task max_element(B first, E last, T &result, C comp, P part)
constructs a task to perform STL-styled max-element algorithm
Task min_element(B first, E last, T &result, C comp, P part)
constructs a task to perform STL-styled min-element algorithm
Task sort(B first, E last)
constructs a dynamic task to perform STL-styled parallel sort using the std::less<T> comparator,...
Task transform_inclusive_scan(B first, E last, D d_first, BOP bop, UOP uop)
creates an STL-styled parallel transform-inclusive scan task
Task transform_exclusive_scan(B first, E last, D d_first, T init, BOP bop, UOP uop)
creates an STL-styled parallel transform-exclusive scan task
void linearize(std::vector< Task > &tasks)
adds adjacent dependency links to a linear list of tasks
Definition flow_builder.hpp:1469
Graph & _graph
associated graph object
Definition flow_builder.hpp:1337
Task transform(B first1, E last1, O d_first, C c, P part=P())
constructs a parallel-transform task
Task find_if_not(B first, E last, T &result, UOP predicate, P part=P())
constructs a task to perform STL-styled find-if-not algorithm
Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first, C cmp, P part=P())
merges two sorted ranges into a single sorted output using the supplied comparator
Task for_each(B first, E last, C callable, P part=P())
constructs an STL-styled parallel-for task
Task transform_reduce(B1 first1, E1 last1, B2 first2, T &init, BOP_R bop_r, BOP_T bop_t, P part=P())
constructs an STL-styled parallel transform-reduce task
Task composed_of(T &object)
creates a module task for the target object
Definition flow_builder.hpp:1402
Task placeholder()
creates a placeholder task
Definition flow_builder.hpp:1416
Task reduce(B first, E last, T &init, O bop, P part=P())
constructs an STL-styled parallel-reduction task
Task transform(B1 first1, E1 last1, B2 first2, O d_first, C c, P part=P())
constructs a parallel-transform task
class to create a graph object
Definition graph.hpp:47
void clear()
clears the graph
Definition graph.hpp:881
class to construct a subflow graph from the execution of a dynamic task
Definition flow_builder.hpp:1516
Executor & executor() noexcept
acquires the associated executor
Definition flow_builder.hpp:1620
Graph & graph()
acquires the associated graph
Definition flow_builder.hpp:1565
void join()
enables the subflow to join its parent task
bool joinable() const noexcept
queries if the subflow is joinable
Definition flow_builder.hpp:1615
bool retain() const
queries if the subflow will be retained after it is joined
Definition flow_builder.hpp:1639
class to create a task handle over a taskflow node
Definition task.hpp:263
class to create a worker in an executor
Definition worker.hpp:55
determines if a type is a partitioner
Definition partitioner.hpp:815
taskflow namespace
Definition small_vector.hpp:20
Graph & retrieve_graph(T &t)
retrieves a reference to the underlying tf::Graph from an object
Definition graph.hpp:975
GuidedPartitioner<> DefaultPartitioner
default partitioner set to tf::GuidedPartitioner
Definition partitioner.hpp:807