4#include "../algorithm/partitioner.hpp"
31template <
typename C,
typename B>
52template <
typename C,
typename B1,
typename B2>
54requires(C c, B1 b1, B2 b2) {
73template <
typename C,
typename B,
typename O>
75requires(C c, B b, O o) {
95template <
typename C,
typename B1,
typename B2,
typename O>
97requires(C c, B1 b1, B2 b2, O o) {
116 friend class Executor;
143 template <StaticTaskLike C>
164 template <RuntimeTaskLike C>
189 template <SubflowTaskLike C>
222 template <ConditionTaskLike C>
256 template <MultiConditionTaskLike C>
283 template <
typename... C>
requires (
sizeof...(C) > 1)
284 auto emplace(C&&... callables);
371 template <GraphLike T>
425 template <GraphLike T>
499 void linearize(std::vector<Task>& tasks);
516 void linearize(std::initializer_list<Task> tasks);
555 template <InputIteratorLike B, InputIteratorLike E,
typename C, PartitionerLike P = DefaultPartitioner>
598 template <
typename B,
typename E,
typename S,
typename C, PartitionerLike P = DefaultPartitioner>
717 template <IndexRangesLike R,
typename C, PartitionerLike P = DefaultPartitioner>
762 std::decay_t<std::unwrap_ref_decay_t<B>>,
763 std::decay_t<std::unwrap_ref_decay_t<O>>
807 std::decay_t<std::unwrap_ref_decay_t<B1>>,
808 std::decay_t<std::unwrap_ref_decay_t<B2>>,
809 std::decay_t<std::unwrap_ref_decay_t<O>>
811 Task transform(B1 first1, E1 last1, B2 first2, O d_first, C c, P part = P());
850 template <InputIteratorLike B, InputIteratorLike E,
typename T,
typename O, PartitionerLike P = DefaultPartitioner>
950 template <IndexRangesLike R,
typename T,
typename L,
typename G, PartitionerLike P = DefaultPartitioner>
1037 std::decay_t<std::unwrap_ref_decay_t<B1>>,
1038 std::decay_t<std::unwrap_ref_decay_t<B2>>
1041 B1 first1, E1 last1, B2 first2, T& init, BOP_R bop_r, BOP_T bop_t, P part = P()
1086 template <InputIteratorLike B, InputIteratorLike E,
typename D,
typename BOP>
1130 template <InputIteratorLike B, InputIteratorLike E,
typename D,
typename BOP,
typename T>
1173 template <InputIteratorLike B, InputIteratorLike E,
typename D,
typename T,
typename BOP>
1221 template <InputIteratorLike B, InputIteratorLike E,
typename D,
typename BOP,
typename UOP>
1268 template <InputIteratorLike B, InputIteratorLike E,
typename D,
typename BOP,
typename UOP,
typename T>
1314 template <InputIteratorLike B, InputIteratorLike E,
typename D,
typename T,
typename BOP,
typename UOP>
1366 template <InputIteratorLike B, InputIteratorLike E,
typename T,
typename UOP, PartitionerLike P = DefaultPartitioner>
1367 Task find_if(B first, E last, T &result, UOP predicate, P part = P());
1414 template <InputIteratorLike B, InputIteratorLike E,
typename T,
typename UOP, PartitionerLike P = DefaultPartitioner>
1466 template <InputIteratorLike B, InputIteratorLike E,
typename T,
typename C, PartitionerLike P>
1518 template <InputIteratorLike B, InputIteratorLike E,
typename T,
typename C, PartitionerLike P>
1544 template <InputIteratorLike B, InputIteratorLike E,
typename C>
1566 template <InputIteratorLike B, InputIteratorLike E>
1602 template <InputIteratorLike B1, InputIteratorLike E1, InputIteratorLike B2, InputIteratorLike E2,
typename O>
1603 Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first);
1642 typename O,
typename C>
1643 Task merge(B1 first1, E1 last1, B2 first2, E2 last2, O d_first, C cmp);
1670 template<InputIteratorLike B, InputIteratorLike E,
typename V, PartitionerLike P = DefaultPartitioner>
1698 template<InputIteratorLike B, std::
integral C,
typename V, PartitionerLike P = DefaultPartitioner>
1728 template <InputIteratorLike B, InputIteratorLike E,
typename G, PartitionerLike P= DefaultPartitioner>
1758 template <InputIteratorLike B, std::
integral C,
typename G, PartitionerLike P = DefaultPartitioner>
1770 template <
typename L>
1771 void _linearize(L&);
1780template <StaticTaskLike C>
1782 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1783 std::in_place_type_t<Node::Static>{}, std::forward<C>(c)
1788template <RuntimeTaskLike C>
1790 if constexpr (std::is_invocable_v<C, tf::Runtime&>) {
1791 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1792 std::in_place_type_t<Node::Runtime>{}, std::forward<C>(c)
1795 else if constexpr (std::is_invocable_v<C, tf::NonpreemptiveRuntime&>) {
1796 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1797 std::in_place_type_t<Node::NonpreemptiveRuntime>{}, std::forward<C>(c)
1801 static_assert(dependent_false_v<C>,
"invalid runtime task callable");
1806template <SubflowTaskLike C>
1808 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1809 std::in_place_type_t<Node::Subflow>{}, std::forward<C>(c)
1814template <ConditionTaskLike C>
1816 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1817 std::in_place_type_t<Node::Condition>{}, std::forward<C>(c)
1822template <MultiConditionTaskLike C>
1824 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE, DefaultTaskParams{},
nullptr,
nullptr, 0,
1825 std::in_place_type_t<Node::MultiCondition>{}, std::forward<C>(c)
1830template <GraphLike T>
1832 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1839 return Task(_graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1840 std::in_place_type_t<Node::AdoptedModule>{}, std::move(graph)
1845template <GraphLike T>
1852 return adopt(std::move(graph));
1857 auto node = _graph._emplace_back(NSTATE::NONE, ESTATE::NONE,
DefaultTaskParams{},
nullptr,
nullptr, 0,
1858 std::in_place_type_t<Node::Placeholder>{}
1864template <
typename... C>
requires (
sizeof...(C) > 1)
1866 return std::make_tuple(
emplace(std::forward<C>(cs))...);
1877 for(
size_t i=0; i<task._node->_num_successors; ++i) {
1878 task._node->_edges[i]->_remove_predecessors(task._node);
1882 for(
size_t i=task._node->_num_successors; i<task._node->_edges.size(); ++i) {
1883 task._node->_edges[i]->_remove_successors(task._node);
1886 _graph._erase(task._node);
1891template <
typename L>
1892void FlowBuilder::_linearize(L& keys) {
1894 auto itr = keys.begin();
1895 auto end = keys.end();
1903 for(++nxt; nxt != end; ++nxt, ++itr) {
1904 itr->_node->_precede(nxt->_node);
1956class Subflow :
public FlowBuilder {
1958 friend class Executor;
1959 friend class FlowBuilder;
2016 void retain(
bool flag)
noexcept;
2041inline Subflow::Subflow(Executor& executor, Worker& worker, Node* node, Graph& graph) :
2042 FlowBuilder {graph},
2043 _executor {executor},
2048 _node->_nstate &= ~(NSTATE::JOINED_SUBFLOW | NSTATE::RETAIN_SUBFLOW);
2056 return !(_node->_nstate & NSTATE::JOINED_SUBFLOW);
2068 _node->_nstate |= NSTATE::RETAIN_SUBFLOW;
2071 _node->_nstate &= ~NSTATE::RETAIN_SUBFLOW;
2080 return _node->_nstate & NSTATE::RETAIN_SUBFLOW;
class to create an empty task parameter for compile-time optimization
Definition graph.hpp:217
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 transform(B1 first1, E1 last1, B2 first2, O d_first, C c, P part=P())
constructs a parallel-transform 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:1838
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 over a one- or multi-dimensional index range
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 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:1781
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:1870
Task for_each(B first, E last, C callable, P part=P())
constructs an STL-styled parallel-for task
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:1775
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:1909
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 transform(B first1, E last1, O d_first, C c, P part=P())
constructs a parallel-transform task
Task composed_of(T &object)
creates a module task for the target object
Definition flow_builder.hpp:1831
Task placeholder()
creates a placeholder task
Definition flow_builder.hpp:1856
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 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:970
class to construct a subflow graph from the execution of a dynamic task
Definition flow_builder.hpp:1956
Executor & executor() noexcept
acquires the associated executor
Definition flow_builder.hpp:2060
Graph & graph()
acquires the associated graph
Definition flow_builder.hpp:2005
void join()
enables the subflow to join its parent task
bool joinable() const noexcept
queries if the subflow is joinable
Definition flow_builder.hpp:2055
bool retain() const
queries if the subflow will be retained after it is joined
Definition flow_builder.hpp:2079
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
concept to check if a binary operation is valid
Definition flow_builder.hpp:53
concept to check if a type is a partitioner
Definition partitioner.hpp:1138
concept to check if a unary operation is valid
Definition flow_builder.hpp:32
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:1108
GuidedPartitioner<> DefaultPartitioner
default partitioner set to tf::GuidedPartitioner
Definition partitioner.hpp:1130