Cpp-Taskflow  2.0.0
tf::FlowBuilder Class Reference

The building blocks of task dependency graphs. More...

#include <flow_builder.hpp>

Inheritance diagram for tf::FlowBuilder:

Public Member Functions

 FlowBuilder (Graph &)
 
template<typename C >
auto emplace (C &&callable)
 creates a 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 at one time More...
 
template<typename C >
auto silent_emplace (C &&callable)
 creates a task from a given callable object without access to the result More...
 
template<typename... C, std::enable_if_t<(sizeof...(C)> 1>
auto silent_emplace (C &&... callables)
 creates multiple tasks from a list of callable objects without access to the results More...
 
template<typename I , typename C >
std::pair< Task, Taskparallel_for (I beg, I end, C &&callable, size_t chunk=0)
 constructs a task dependency graph of range-based parallel_for More...
 
template<typename I , typename C , std::enable_if_t< std::is_arithmetic_v< I >, void > * = nullptr>
std::pair< Task, Taskparallel_for (I beg, I end, I step, C &&callable, size_t chunk=0)
 constructs a task dependency graph of 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 gather (std::vector< Task > &others, Task A)
 adds dependency links from many tasks to one task A More...
 
void gather (std::initializer_list< Task > others, Task A)
 adds dependency links from many tasks to one task A More...
 

Detailed Description

The building blocks of task dependency graphs.

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

◆ emplace() [1/2]

template<typename C >
auto tf::FlowBuilder::emplace ( C &&  callable)

creates a task from a given callable object

Template Parameters
Ccallable type
Parameters
callablea callable object acceptable to std::function
Returns
a std::pair of Task handle and std::future

◆ emplace() [2/2]

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 at one time

Template Parameters
C...callable types
Parameters
callablesone or multiple callable objects acceptable to std::function
Returns
a std::tuple of pairs of Task Handle and std::future

◆ gather() [1/2]

void tf::FlowBuilder::gather ( 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

◆ gather() [2/2]

void tf::FlowBuilder::gather ( 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

◆ 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/2]

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

constructs a task dependency graph of range-based parallel_for

The task dependency graph applies a callable object to the dereferencing of every iterator in the range [beg, end) chunk-by-chunk.

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
chunknumber of works per thread
Returns
a pair of Task handles to the beginning and the end of the graph

◆ parallel_for() [2/2]

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

constructs a task dependency graph of 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
Iarithmetic index type
Ccallable type
Parameters
begindex to the beginning (inclusive)
endindex to the end (exclusive)
stepstep size
callablea callable object to be applied to
chunknumber of works per thread
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

◆ silent_emplace() [1/2]

template<typename C >
auto tf::FlowBuilder::silent_emplace ( C &&  callable)

creates a task from a given callable object without access to the result

Template Parameters
Ccallable type
Parameters
callablea callable object acceptable to std::function
Returns
a Task handle

◆ silent_emplace() [2/2]

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

creates multiple tasks from a list of callable objects without access to the results

Template Parameters
C...callable types
Parameters
callablesone or multiple callable objects acceptable to std::function
Returns
a tuple of Task handles

◆ 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: