Taskflow  2.4-master-branch
tf::FlowBuilder Class Reference

building methods of a task dependency graph More...

#include <flow_builder.hpp>

Inheritance diagram for tf::FlowBuilder:

Public Member Functions

 FlowBuilder (Graph &graph)
 constructs a flow builder object More...
 
template<typename C >
std::enable_if_t< is_static_task_v< C >, Taskemplace (C &&callable)
 creates a static task from a given callable object More...
 
template<typename C >
std::enable_if_t< is_dynamic_task_v< C >, Taskemplace (C &&callable)
 creates a dynamic task from a given callable object More...
 
template<typename C >
std::enable_if_t< is_condition_task_v< C >, Taskemplace (C &&callable)
 creates a condition task from a given callable object More...
 
template<typename C >
std::enable_if_t< is_cudaflow_task_v< C >, Taskemplace (C &&callable)
 creates a cudaflow task from a given callable object More...
 
template<typename... C, std::enable_if_t<(sizeof...(C)> 1>
auto emplace (C &&... callables)
 creates multiple tasks from a list of callable objects More...
 
Task composed_of (Taskflow &taskflow)
 creates a module task from a taskflow More...
 
template<typename I , typename C >
std::pair< Task, Taskparallel_for (I beg, I end, C &&callable, size_t chunk=1)
 constructs a task dependency graph of range-based parallel_for More...
 
template<typename I , typename C , std::enable_if_t< std::is_integral< std::decay_t< I >>::value, void > * = nullptr>
std::pair< Task, Taskparallel_for (I beg, I end, I step, C &&callable, size_t chunk=1)
 constructs a task dependency graph of integer index-based parallel_for More...
 
template<typename I , typename C , std::enable_if_t< std::is_floating_point< std::decay_t< I >>::value, void > * = nullptr>
std::pair< Task, Taskparallel_for (I beg, I end, I step, C &&callable, size_t chunk=1)
 constructs a task dependency graph of floating index-based parallel_for More...
 
template<typename I , typename T , typename B >
std::pair< Task, Taskreduce (I beg, I end, T &result, B &&bop)
 construct a task dependency graph of parallel reduction More...
 
template<typename I , typename T >
std::pair< Task, Taskreduce_min (I beg, I end, T &result)
 constructs a task dependency graph of parallel reduction through std::min More...
 
template<typename I , typename T >
std::pair< Task, Taskreduce_max (I beg, I end, T &result)
 constructs a task dependency graph of parallel reduction through std::max More...
 
template<typename I , typename T , typename B , typename U >
std::pair< Task, Tasktransform_reduce (I beg, I end, T &result, B &&bop, U &&uop)
 constructs a task dependency graph of parallel transformation and reduction More...
 
template<typename I , typename T , typename B , typename P , typename U >
std::pair< Task, Tasktransform_reduce (I beg, I end, T &result, B &&bop1, P &&bop2, U &&uop)
 constructs a task dependency graph of parallel transformation and reduction More...
 
Task placeholder ()
 creates an empty task More...
 
void precede (Task A, Task B)
 adds a dependency link from task A to task B More...
 
void linearize (std::vector< Task > &tasks)
 adds adjacent dependency links to a linear list of tasks More...
 
void linearize (std::initializer_list< Task > tasks)
 adds adjacent dependency links to a linear list of tasks More...
 
void broadcast (Task A, std::vector< Task > &others)
 adds dependency links from one task A to many tasks More...
 
void broadcast (Task A, std::initializer_list< Task > others)
 adds dependency links from one task A to many tasks More...
 
void succeed (std::vector< Task > &others, Task A)
 adds dependency links from many tasks to one task A More...
 
void succeed (std::initializer_list< Task > others, Task A)
 adds dependency links from many tasks to one task A More...
 

Friends

class Task
 

Detailed Description

building methods of a task dependency graph

Constructor & Destructor Documentation

◆ FlowBuilder()

tf::FlowBuilder::FlowBuilder ( Graph &  graph)
inline

constructs a flow builder object

Parameters
grapha task dependency graph to manipulate

Member Function Documentation

◆ broadcast() [1/2]

void tf::FlowBuilder::broadcast ( Task  A,
std::vector< Task > &  others 
)
inline

adds dependency links from one task A to many tasks

Parameters
Atask A
othersa task set which A precedes

◆ broadcast() [2/2]

void tf::FlowBuilder::broadcast ( Task  A,
std::initializer_list< Task others 
)
inline

adds dependency links from one task A to many tasks

Parameters
Atask A
othersa task set which A precedes

◆ composed_of()

Task tf::FlowBuilder::composed_of ( Taskflow taskflow)
inline

creates a module task from a taskflow

Parameters
taskflowa taskflow object for the module
Returns
a Task handle

◆ emplace() [1/5]

template<typename C >
std::enable_if_t< is_static_task_v< C >, Task > tf::FlowBuilder::emplace ( C &&  callable)

creates a static task from a given callable object

Template Parameters
Ccallable type
Parameters
callablea callable object constructible from std::function<void()>
Returns
Task handle

◆ emplace() [2/5]

template<typename C >
std::enable_if_t< is_dynamic_task_v< C >, Task > tf::FlowBuilder::emplace ( C &&  callable)

creates a dynamic task from a given callable object

Template Parameters
Ccallable type
Parameters
callablea callable object constructible from std::function<void(Subflow&)>
Returns
Task handle

◆ emplace() [3/5]

template<typename C >
std::enable_if_t< is_condition_task_v< C >, Task > tf::FlowBuilder::emplace ( C &&  callable)

creates a condition task from a given callable object

Template Parameters
Ccallable type
Parameters
callablea callable object constructible from std::function<int()>
Returns
Task handle

◆ emplace() [4/5]

template<typename C >
std::enable_if_t< is_cudaflow_task_v< C >, Task > tf::FlowBuilder::emplace ( C &&  callable)

creates a cudaflow task from a given callable object

Template Parameters
Ccallable type
Parameters
callablea callable object constructible from std::function<void(cudaFlow&)>
Returns
Task handle

◆ emplace() [5/5]

template<typename... C, std::enable_if_t<(sizeof...(C)> 1>
auto tf::FlowBuilder::emplace ( C &&...  callables)

creates multiple tasks from a list of callable objects

Template Parameters
C...callable types
Parameters
callablesone or multiple callable objects constructible from each task category
Returns
a Task handle

◆ linearize() [1/2]

void tf::FlowBuilder::linearize ( std::vector< Task > &  tasks)
inline

adds adjacent dependency links to a linear list of tasks

Parameters
tasksa vector of tasks

◆ linearize() [2/2]

void tf::FlowBuilder::linearize ( std::initializer_list< Task tasks)
inline

adds adjacent dependency links to a linear list of tasks

Parameters
tasksan initializer list of tasks

◆ parallel_for() [1/3]

template<typename I , typename C >
std::pair< Task, Task > tf::FlowBuilder::parallel_for ( beg,
end,
C &&  callable,
size_t  chunk = 1 
)

constructs a task dependency graph of range-based parallel_for

The task dependency graph applies the callable object callable to each object obtained by dereferencing every iterator in the range [beg, end). The range is split into chunks of size chunk, where each of them is processed by one Task.

The callable needs to accept a single argument, the object in the range.

Template Parameters
Iinput iterator type
Ccallable type
Parameters
begiterator to the beginning (inclusive)
enditerator to the end (exclusive)
callablea callable object to be applied to
chunksize (default 1)
Returns
a pair of Task handles to the beginning and the end of the graph

◆ parallel_for() [2/3]

template<typename I , typename C , std::enable_if_t< std::is_floating_point< std::decay_t< I >>::value, void > * >
std::pair< Task, Task > tf::FlowBuilder::parallel_for ( beg,
end,
step,
C &&  callable,
size_t  chunk = 1 
)

constructs a task dependency graph of integer index-based parallel_for

The task dependency graph applies a callable object to every index in the range [beg, end) with a step size chunk by chunk.

Template Parameters
Iinteger (arithmetic) index type
Ccallable type
Parameters
begindex of the beginning (inclusive)
endindex of the end (exclusive)
stepstep size
callablea callable object to be applied to
chunkitems per task
Returns
a pair of Task handles to the beginning and the end of the graph

◆ parallel_for() [3/3]

template<typename I , typename C , std::enable_if_t< std::is_floating_point< std::decay_t< I >>::value, void > * = nullptr>
std::pair<Task, Task> tf::FlowBuilder::parallel_for ( beg,
end,
step,
C &&  callable,
size_t  chunk = 1 
)

constructs a task dependency graph of floating index-based parallel_for

The task dependency graph applies a callable object to every index in the range [beg, end) with a step size chunk by chunk.

Template Parameters
Ifloating (arithmetic) index type
Ccallable type
Parameters
begindex of the beginning (inclusive)
endindex of the end (exclusive)
stepstep size
callablea callable object to be applied to
chunkitems per task
Returns
a pair of Task handles to the beginning and the end of the graph

◆ placeholder()

Task tf::FlowBuilder::placeholder ( )
inline

creates an empty task

Returns
a Task handle

◆ precede()

void tf::FlowBuilder::precede ( Task  A,
Task  B 
)
inline

adds a dependency link from task A to task B

Parameters
Atask A
Btask B

◆ reduce()

template<typename I , typename T , typename B >
std::pair< Task, Task > tf::FlowBuilder::reduce ( beg,
end,
T &  result,
B &&  bop 
)

construct a task dependency graph of parallel reduction

The task dependency graph reduces items in the range [beg, end) to a single result.

Template Parameters
Iinput iterator type
Tdata type
Bbinary operator type
Parameters
begiterator to the beginning (inclusive)
enditerator to the end (exclusive)
resultreference variable to store the final result
bopbinary operator that will be applied in unspecified order to the result of dereferencing the input iterator
Returns
a pair of Task handles to the beginning and the end of the graph

◆ reduce_max()

template<typename I , typename T >
std::pair< Task, Task > tf::FlowBuilder::reduce_max ( beg,
end,
T &  result 
)

constructs a task dependency graph of parallel reduction through std::max

The task dependency graph applies a parallel reduction to find the maximum item in the range [beg, end) through std::max reduction.

Template Parameters
Iinput iterator type
Tdata type
Parameters
begiterator to the beginning (inclusive)
enditerator to the end (exclusive)
resultreference variable to store the final result
Returns
a pair of Task handles to the beginning and the end of the graph

◆ reduce_min()

template<typename I , typename T >
std::pair< Task, Task > tf::FlowBuilder::reduce_min ( beg,
end,
T &  result 
)

constructs a task dependency graph of parallel reduction through std::min

The task dependency graph applies a parallel reduction to find the minimum item in the range [beg, end) through std::min reduction.

Template Parameters
Iinput iterator type
Tdata type
Parameters
begiterator to the beginning (inclusive)
enditerator to the end (exclusive)
resultreference variable to store the final result
Returns
a pair of Task handles to the beginning and the end of the graph

◆ succeed() [1/2]

void tf::FlowBuilder::succeed ( std::vector< Task > &  others,
Task  A 
)
inline

adds dependency links from many tasks to one task A

Parameters
othersa task set to precede A
Atask A

◆ succeed() [2/2]

void tf::FlowBuilder::succeed ( std::initializer_list< Task others,
Task  A 
)
inline

adds dependency links from many tasks to one task A

Parameters
othersa task set to precede A
Atask A

◆ transform_reduce() [1/2]

template<typename I , typename T , typename B , typename U >
std::pair< Task, Task > tf::FlowBuilder::transform_reduce ( beg,
end,
T &  result,
B &&  bop,
U &&  uop 
)

constructs a task dependency graph of parallel transformation and reduction

The task dependency graph transforms each item in the range [beg, end) into a new data type and then reduce the results.

Template Parameters
Iinput iterator type
Tdata type
Bbinary operator
Uunary operator type
Parameters
begiterator to the beginning (inclusive)
enditerator to the end (exclusive)
resultreference variable to store the final result
bopbinary function object that will be applied in unspecified order to the results of uop; the return type must be T
uopunary function object that transforms each element in the input range; the return type must be acceptable as input to bop
Returns
a pair of Task handles to the beginning and the end of the graph

◆ transform_reduce() [2/2]

template<typename I , typename T , typename B , typename P , typename U >
std::pair< Task, Task > tf::FlowBuilder::transform_reduce ( beg,
end,
T &  result,
B &&  bop1,
P &&  bop2,
U &&  uop 
)

constructs a task dependency graph of parallel transformation and reduction

The task dependency graph transforms each item in the range [beg, end) into a new data type and then apply two-layer reductions to derive the result.

Template Parameters
Iinput iterator type
Tdata type
Bbinary operator type
Pbinary operator type
Uunary operator type
Parameters
begiterator to the beginning (inclusive)
enditerator to the end (exclusive)
resultreference variable to store the final result
bop1binary function object that will be applied in the second-layer reduction to the results of bop2
bop2binary function object that will be applied in the first-layer reduction to the results of uop and the dereferencing of input iterators
uopunary function object that will be applied to transform an item to a new data type that is acceptable as input to bop2
Returns
a pair of Task handles to the beginning and the end of the graph

The documentation for this class was generated from the following file: