4#include "../algorithm/partitioner.hpp"
24 friend class Executor;
51 template <StaticTaskLike C>
72 template <RuntimeTaskLike C>
97 template <SubflowTaskLike C>
130 template <ConditionTaskLike C>
164 template <MultiConditionTaskLike C>
191 template <
typename... C>
requires (
sizeof...(C) > 1)
192 auto emplace(C&&... callables);
279 template <GraphLike T>
348 void linearize(std::vector<Task>& tasks);
365 void linearize(std::initializer_list<Task> tasks);
404 template <
typename B,
typename E,
typename C, PartitionerLike P = DefaultPartitioner>
446 template <
typename B,
typename E,
typename S,
typename C, PartitionerLike P = DefaultPartitioner>
565 template <IndexRangesLike R,
typename C, PartitionerLike P = DefaultPartitioner>
606 template <
typename B,
typename E,
typename O,
typename C,
646 template <
typename B1,
typename E1,
typename B2,
typename O,
typename C,
649 Task transform(B1 first1, E1 last1, B2 first2, O d_first, C c, P part = P());
688 template <
typename B,
typename E,
typename T,
typename O, PartitionerLike P = DefaultPartitioner>
745 template <IndexRanges1DLike R,
typename T,
typename L,
typename G, PartitionerLike P = DefaultPartitioner>
787 template <
typename B,
typename E,
typename T,
typename BOP,
typename UOP,
828 template <
typename B1,
typename E1,
typename B2,
typename T,
832 B1 first1, E1 last1, B2 first2, T& init, BOP_R bop_r, BOP_T bop_t, P part = P()
877 template <
typename B,
typename E,
typename D,
typename BOP>
921 template <
typename B,
typename E,
typename D,
typename BOP,
typename T>
964 template <
typename B,
typename E,
typename D,
typename T,
typename BOP>
1012 template <
typename B,
typename E,
typename D,
typename BOP,
typename UOP>
1059 template <
typename B,
typename E,
typename D,
typename BOP,
typename UOP,
typename T>
1105 template <
typename B,
typename E,
typename D,
typename T,
typename BOP,
typename UOP>
1157 template <
typename B,
typename E,
typename T,
typename UOP, PartitionerLike P = DefaultPartitioner>
1158 Task find_if(B first, E last, T &result, UOP predicate, P part = P());
1205 template <
typename B,
typename E,
typename T,
typename UOP, PartitionerLike P = DefaultPartitioner>
1257 template <
typename B,
typename E,
typename T,
typename C, PartitionerLike P>
1309 template <
typename B,
typename E,
typename T,
typename C, PartitionerLike P>
1335 template <
typename B,
typename E,
typename C>
1357 template <
typename B,
typename E>
1393 template <
typename B1,
typename E1,
typename B2,
typename E2,
typename O>
1394 Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first);
1431 template <
typename B1,
typename E1,
typename B2,
typename E2,
1432 typename O,
typename C>
1433 Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first, C cmp);
1460 template<
typename B,
typename E,
typename V, PartitionerLike P = DefaultPartitioner>
1488 template<
typename B, std::
integral C,
typename V, PartitionerLike P = DefaultPartitioner>
1518 template <
typename B,
typename E,
typename G, PartitionerLike P= DefaultPartitioner>
1548 template <
typename B, std::
integral C,
typename G, PartitionerLike P = DefaultPartitioner>
1560 template <
typename L>
1561 void _linearize(L&);
1570template <StaticTaskLike C>
1572 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1573 std::in_place_type_t<Node::Static>{}, std::forward<C>(c)
1578template <RuntimeTaskLike C>
1580 if constexpr (std::is_invocable_v<C, tf::Runtime&>) {
1581 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1582 std::in_place_type_t<Node::Runtime>{}, std::forward<C>(c)
1585 else if constexpr (std::is_invocable_v<C, tf::NonpreemptiveRuntime&>) {
1586 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1587 std::in_place_type_t<Node::NonpreemptiveRuntime>{}, std::forward<C>(c)
1591 static_assert(dependent_false_v<C>,
"invalid runtime task callable");
1596template <SubflowTaskLike C>
1598 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1599 std::in_place_type_t<Node::Subflow>{}, std::forward<C>(c)
1604template <ConditionTaskLike C>
1606 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1607 std::in_place_type_t<Node::Condition>{}, std::forward<C>(c)
1612template <MultiConditionTaskLike C>
1614 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1615 std::in_place_type_t<Node::MultiCondition>{}, std::forward<C>(c)
1620template <GraphLike T>
1622 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1629 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1630 std::in_place_type_t<Node::AdoptedModule>{}, std::move(graph)
1636 auto node = _graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1637 std::in_place_type_t<Node::Placeholder>{}
1643template <
typename... C>
requires (
sizeof...(C) > 1)
1645 return std::make_tuple(
emplace(std::forward<C>(cs))...);
1656 for(
size_t i=0; i<task._node->_num_successors; ++i) {
1657 task._node->_edges[i]->_remove_predecessors(task._node);
1661 for(
size_t i=task._node->_num_successors; i<task._node->_edges.size(); ++i) {
1662 task._node->_edges[i]->_remove_successors(task._node);
1665 _graph._erase(task._node);
1670template <
typename L>
1671void FlowBuilder::_linearize(L& keys) {
1673 auto itr = keys.begin();
1674 auto end = keys.end();
1682 for(++nxt; nxt != end; ++nxt, ++itr) {
1683 itr->_node->_precede(nxt->_node);
1735class Subflow :
public FlowBuilder {
1737 friend class Executor;
1738 friend class FlowBuilder;
1795 void retain(
bool flag)
noexcept;
1820inline Subflow::Subflow(Executor& executor, Worker& worker, Node* node, Graph& graph) :
1821 FlowBuilder {graph},
1822 _executor {executor},
1827 _node->_nstate &= ~(NSTATE::JOINED_SUBFLOW | NSTATE::RETAIN_SUBFLOW);
1835 return !(_node->_nstate & NSTATE::JOINED_SUBFLOW);
1847 _node->_nstate |= NSTATE::RETAIN_SUBFLOW;
1850 _node->_nstate &= ~NSTATE::RETAIN_SUBFLOW;
1859 return _node->_nstate & NSTATE::RETAIN_SUBFLOW;
class to create an empty task parameter for compile-time optimization
Definition graph.hpp:191
class to create an executor
Definition executor.hpp:62
Task transform(B first1, E last1, O d_first, C c, P part=P())
constructs a parallel-transform task
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 transform(B1 first1, E1 last1, B2 first2, O d_first, C c, P part=P())
constructs a parallel-transform task
Task inclusive_scan(B first, E last, D d_first, BOP bop)
creates an STL-styled parallel inclusive-scan task
Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first, C cmp)
merges two sorted ranges into a single sorted output using a custom comparator
Task for_each_by_index(R range, C callable, P part=P())
constructs a parallel-for task over a one- or multi-dimensional index range
Task sort(B first, E last, C cmp)
constructs a dynamic task to perform STL-styled parallel sort
Task adopt(Graph &&graph)
creates a module task from a graph by taking over its ownership
Definition flow_builder.hpp:1628
Task generate_n(B first, C count, G gen, P part=P())
generates N values into a range in parallel using a callable
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:1571
Task exclusive_scan(B first, E last, D d_first, T init, BOP bop)
creates an STL-styled parallel exclusive-scan task
Task transform_reduce(B first, E last, T &init, BOP bop, UOP uop, P part=P())
constructs an STL-styled parallel transform-reduce task
void erase(Task task)
removes a task from a taskflow
Definition flow_builder.hpp:1649
Task fill(B first, E last, V value, P part=P())
fills a range with a given value in parallel
FlowBuilder(Graph &graph)
constructs a flow builder with a graph
Definition flow_builder.hpp:1565
Task fill_n(B first, C count, V value, P part=P())
fills N elements with a given value in parallel
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 generate(B first, E last, G gen, P part=P())
generates values into a range in parallel using a callable
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:1688
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 for_each(B first, E last, C callable, P part=P())
constructs an STL-styled parallel-for task
Task composed_of(T &object)
creates a module task for the target object
Definition flow_builder.hpp:1621
Task placeholder()
creates a placeholder task
Definition flow_builder.hpp:1635
Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first)
merges two sorted ranges into a single sorted output using the std::less comparator
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 reduce(B first, E last, T &init, O bop, P part=P())
constructs an STL-styled parallel-reduction task
class to create a graph object
Definition graph.hpp:47
void clear()
clears the graph
Definition graph.hpp:929
class to construct a subflow graph from the execution of a dynamic task
Definition flow_builder.hpp:1735
Executor & executor() noexcept
acquires the associated executor
Definition flow_builder.hpp:1839
Graph & graph()
acquires the associated graph
Definition flow_builder.hpp:1784
void join()
enables the subflow to join its parent task
bool joinable() const noexcept
queries if the subflow is joinable
Definition flow_builder.hpp:1834
bool retain() const
queries if the subflow will be retained after it is joined
Definition flow_builder.hpp:1858
class to create a task handle over a taskflow node
Definition task.hpp:569
class to create a worker in an executor
Definition worker.hpp:55
determines if a type is a partitioner
Definition partitioner.hpp:906
taskflow namespace
Definition small_vector.hpp:20
Graph & retrieve_graph(T &target)
retrieves a reference to the underlying tf::Graph from an object
Definition graph.hpp:1067
GuidedPartitioner<> DefaultPartitioner
default partitioner set to tf::GuidedPartitioner
Definition partitioner.hpp:898