Taskflow  2.7.0
tf::FlowBuilder Class Reference

building methods of a task dependency graph More...

#include <flow_builder.hpp>

Inheritance diagram for tf::FlowBuilder:

Public Member Functions

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...
 
Task placeholder ()
 creates an empty task 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...
 
template<typename B , typename E , typename C >
Task for_each (B &&first, E &&last, C &&callable)
 constructs a STL-styled parallel-for task More...
 
template<typename B , typename E , typename C , typename H = size_t>
Task for_each_guided (B &&beg, E &&end, C &&callable, H &&chunk_size=1)
 constructs a STL-styled parallel-for task using the guided partition algorithm More...
 
template<typename B , typename E , typename C , typename H = size_t>
Task for_each_dynamic (B &&beg, E &&end, C &&callable, H &&chunk_size=1)
 constructs a STL-styled parallel-for task using the dynamic partition algorithm More...
 
template<typename B , typename E , typename C , typename H = size_t>
Task for_each_static (B &&beg, E &&end, C &&callable, H &&chunk_size=0)
 constructs a STL-styled parallel-for task using the dynamic partition algorithm More...
 
template<typename B , typename E , typename S , typename C >
Task for_each_index (B &&first, E &&last, S &&step, C &&callable)
 constructs an index-based parallel-for task More...
 
template<typename B , typename E , typename S , typename C , typename H = size_t>
Task for_each_index_guided (B &&beg, E &&end, S &&step, C &&callable, H &&chunk_size=1)
 constructs an index-based parallel-for task using the guided partition algorithm. More...
 
template<typename B , typename E , typename S , typename C , typename H = size_t>
Task for_each_index_dynamic (B &&beg, E &&end, S &&step, C &&callable, H &&chunk_size=1)
 constructs an index-based parallel-for task using the dynamic partition algorithm. More...
 
template<typename B , typename E , typename S , typename C , typename H = size_t>
Task for_each_index_static (B &&beg, E &&end, S &&step, C &&callable, H &&chunk_size=0)
 constructs an index-based parallel-for task using the static partition algorithm. More...
 
template<typename B , typename E , typename T , typename O >
Task reduce (B &&first, E &&last, T &init, O &&bop)
 constructs a STL-styled parallel-reduce task More...
 
template<typename B , typename E , typename T , typename O , typename H = size_t>
Task reduce_guided (B &&first, E &&last, T &init, O &&bop, H &&chunk_size=1)
 constructs a STL-styled parallel-reduce task using the guided partition algorithm More...
 
template<typename B , typename E , typename T , typename O , typename H = size_t>
Task reduce_dynamic (B &&first, E &&last, T &init, O &&bop, H &&chunk_size=1)
 constructs a STL-styled parallel-reduce task using the dynamic partition algorithm More...
 
template<typename B , typename E , typename T , typename O , typename H = size_t>
Task reduce_static (B &&first, E &&last, T &init, O &&bop, H &&chunk_size=0)
 constructs a STL-styled parallel-reduce task using the static partition algorithm More...
 
template<typename B , typename E , typename T , typename BOP , typename UOP >
Task transform_reduce (B &&first, E &&last, T &init, BOP &&bop, UOP &&uop)
 constructs a STL-styled parallel transform-reduce task More...
 
template<typename B , typename E , typename T , typename BOP , typename UOP , typename H = size_t>
Task transform_reduce_guided (B &&first, E &&last, T &init, BOP &&bop, UOP &&uop, H &&chunk_size=1)
 constructs a STL-styled parallel transform-reduce task using the guided partition algorithm More...
 
template<typename B , typename E , typename T , typename BOP , typename UOP , typename H = size_t>
Task transform_reduce_static (B &&first, E &&last, T &init, BOP &&bop, UOP &&uop, H &&chunk_size=0)
 constructs a STL-styled parallel transform-reduce task using the static partition algorithm More...
 
template<typename B , typename E , typename T , typename BOP , typename UOP , typename H = size_t>
Task transform_reduce_dynamic (B &&first, E &&last, T &init, BOP &&bop, UOP &&uop, H &&chunk_size=1)
 constructs a STL-styled parallel transform-reduce task using the dynamic partition algorithm More...
 

Protected Member Functions

 FlowBuilder (Graph &graph)
 constructs a flow builder with a graph
 

Protected Attributes

Graph & _graph
 associated graph object
 

Friends

class Executor
 

Detailed Description

building methods of a task dependency graph

Member Function Documentation

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

◆ for_each()

template<typename B , typename E , typename C >
Task tf::FlowBuilder::for_each ( B &&  first,
E &&  last,
C &&  callable 
)

constructs a STL-styled parallel-for task

Template Parameters
Bbeginning iterator type
Eending iterator type
Ccallable type
Parameters
firstiterator to the beginning (inclusive)
lastiterator to the end (exclusive)
callablea callable object to apply to the dereferenced iterator
Returns
a Task handle

The task spawns a subflow that applies the callable object to each object obtained by dereferencing every iterator in the range [first, last). By default, we employ the guided partition algorithm with chunk size equal to one.

This method is equivalent to the parallel execution of the following loop:

for(auto itr=first; itr!=last; itr++) {
callable(*itr);
}

Arguments templated to enable stateful passing using std::reference_wrapper.

The callable needs to take a single argument of the dereferenced type.

◆ for_each_dynamic()

template<typename B , typename E , typename C , typename H = size_t>
Task tf::FlowBuilder::for_each_dynamic ( B &&  beg,
E &&  end,
C &&  callable,
H &&  chunk_size = 1 
)

constructs a STL-styled parallel-for task using the dynamic partition algorithm

Template Parameters
Bbeginning iterator type
Eending iterator type
Ccallable type
Hchunk size type
Parameters
begiterator to the beginning (inclusive)
enditerator to the end (exclusive)
callablea callable object to apply to the dereferenced iterator
chunk_sizechunk size
Returns
a Task handle

The task spawns a subflow that applies the callable object to each object obtained by dereferencing every iterator in the range [beg, end). The runtime partitions the range into chunks of the given chunk size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.

The callable needs to take a single argument of the dereferenced type.

◆ for_each_guided()

template<typename B , typename E , typename C , typename H = size_t>
Task tf::FlowBuilder::for_each_guided ( B &&  beg,
E &&  end,
C &&  callable,
H &&  chunk_size = 1 
)

constructs a STL-styled parallel-for task using the guided partition algorithm

Template Parameters
Bbeginning iterator type
Eending iterator type
Ccallable type
Hchunk size type
Parameters
begiterator to the beginning (inclusive)
enditerator to the end (exclusive)
callablea callable object to apply to the dereferenced iterator
chunk_sizechunk size
Returns
a Task handle

The task spawns a subflow that applies the callable object to each object obtained by dereferencing every iterator in the range [beg, end). The runtime partitions the range into chunks of the given chunk size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.

The callable needs to take a single argument of the dereferenced type.

◆ for_each_index()

template<typename B , typename E , typename S , typename C >
Task tf::FlowBuilder::for_each_index ( B &&  first,
E &&  last,
S &&  step,
C &&  callable 
)

constructs an index-based parallel-for task

Template Parameters
Bbeginning index type (must be integral)
Eending index type (must be integral)
Sstep type (must be integral)
Ccallable type
Parameters
firstindex of the beginning (inclusive)
lastindex of the end (exclusive)
stepstep size
callablea callable object to apply to each valid index
Returns
a Task handle

The task spawns a subflow that applies the callable object to each index in the range [first, last) with the step size. By default, we employ the guided partition algorithm with chunk size equal to one.

This method is equivalent to the parallel execution of the following loop:

// case 1: step size is positive
for(auto i=first; i<last; i+=step) {
callable(i);
}
// case 2: step size is negative
for(auto i=first, i>last; i+=step) {
callable(i);
}

Arguments are templated to enable stateful passing using std::reference_wrapper.

The callable needs to take a single argument of the index type.

◆ for_each_index_dynamic()

template<typename B , typename E , typename S , typename C , typename H = size_t>
Task tf::FlowBuilder::for_each_index_dynamic ( B &&  beg,
E &&  end,
S &&  step,
C &&  callable,
H &&  chunk_size = 1 
)

constructs an index-based parallel-for task using the dynamic partition algorithm.

Template Parameters
Bbeginning index type (must be integral)
Eending index type (must be integral)
Sstep type (must be integral)
Ccallable type
Hchunk size type
Parameters
begindex of the beginning (inclusive)
endindex of the end (exclusive)
stepstep size
callablea callable object to apply to each valid index
chunk_sizechunk size (default 1)
Returns
a Task handle

The task spawns a subflow that applies the callable object to each index in the range [beg, end) with the step size. The runtime partitions the range into chunks of the given size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.

The callable needs to take a single argument of the index type.

◆ for_each_index_guided()

template<typename B , typename E , typename S , typename C , typename H = size_t>
Task tf::FlowBuilder::for_each_index_guided ( B &&  beg,
E &&  end,
S &&  step,
C &&  callable,
H &&  chunk_size = 1 
)

constructs an index-based parallel-for task using the guided partition algorithm.

Template Parameters
Bbeginning index type (must be integral)
Eending index type (must be integral)
Sstep type (must be integral)
Ccallable type
Hchunk size type
Parameters
begindex of the beginning (inclusive)
endindex of the end (exclusive)
stepstep size
callablea callable object to apply to each valid index
chunk_sizechunk size (default 1)
Returns
a Task handle

The task spawns a subflow that applies the callable object to each index in the range [beg, end) with the step size. The runtime partitions the range into chunks of the given size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.

The callable needs to take a single argument of the index type.

◆ for_each_index_static()

template<typename B , typename E , typename S , typename C , typename H = size_t>
Task tf::FlowBuilder::for_each_index_static ( B &&  beg,
E &&  end,
S &&  step,
C &&  callable,
H &&  chunk_size = 0 
)

constructs an index-based parallel-for task using the static partition algorithm.

Template Parameters
Bbeginning index type (must be integral)
Eending index type (must be integral)
Sstep type (must be integral)
Ccallable type
Hchunk size type
Parameters
begindex of the beginning (inclusive)
endindex of the end (exclusive)
stepstep size
callablea callable object to apply to each valid index
chunk_sizechunk size (default 0)
Returns
a Task handle

The task spawns a subflow that applies the callable object to each index in the range [beg, end) with the step size. The runtime partitions the range into chunks of the given size, where each chunk is processed by a worker. When the given chunk size is zero, the runtime distributes the work evenly across workers.

Arguments are templated to enable stateful passing using std::reference_wrapper.

The callable needs to take a single argument of the index type.

◆ for_each_static()

template<typename B , typename E , typename C , typename H = size_t>
Task tf::FlowBuilder::for_each_static ( B &&  beg,
E &&  end,
C &&  callable,
H &&  chunk_size = 0 
)

constructs a STL-styled parallel-for task using the dynamic partition algorithm

Template Parameters
Bbeginning iterator type
Eending iterator type
Ccallable type
Hchunk size type
Parameters
begiterator to the beginning (inclusive)
enditerator to the end (exclusive)
callablea callable object to apply to the dereferenced iterator
chunk_sizechunk size
Returns
a Task handle

The task spawns a subflow that applies the callable object to each object obtained by dereferencing every iterator in the range [beg, end). The runtime partitions the range into chunks of the given chunk size, where each chunk is processed by a worker. When the given chunk size is zero, the runtime distributes the work evenly across workers.

Arguments are templated to enable stateful passing using std::reference_wrapper.

The callable needs to take a single argument of the dereferenced type.

◆ 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

◆ placeholder()

Task tf::FlowBuilder::placeholder ( )
inline

creates an empty task

Returns
a Task handle

◆ reduce()

template<typename B , typename E , typename T , typename O >
Task tf::FlowBuilder::reduce ( B &&  first,
E &&  last,
T &  init,
O &&  bop 
)

constructs a STL-styled parallel-reduce task

Template Parameters
Bbeginning iterator type
Eending iterator type
Tresult type
Obinary reducer type
Parameters
firstiterator to the beginning (inclusive)
lastiterator to the end (exclusive)
initinitial value of the reduction and the storage for the reduced result
bopbinary operator that will be applied
Returns
a Task handle

The task spawns a subflow to perform parallel reduction over init and the elements in the range [first, last). The reduced result is store in init. The runtime partitions the range into chunks of the given chunk size, where each chunk is processed by a worker. By default, we employ the guided partition algorithm.

This method is equivalent to the parallel execution of the following loop:

for(auto itr=first; itr!=last; itr++) {
init = bop(init, *itr);
}

Arguments are templated to enable stateful passing using std::reference_wrapper.

◆ reduce_dynamic()

template<typename B , typename E , typename T , typename O , typename H = size_t>
Task tf::FlowBuilder::reduce_dynamic ( B &&  first,
E &&  last,
T &  init,
O &&  bop,
H &&  chunk_size = 1 
)

constructs a STL-styled parallel-reduce task using the dynamic partition algorithm

Template Parameters
Bbeginning iterator type
Eending iterator type
Tresult type
Obinary reducer type
Hchunk size type
Parameters
firstiterator to the beginning (inclusive)
lastiterator to the end (exclusive)
initinitial value of the reduction and the storage for the reduced result
bopbinary operator that will be applied
chunk_sizechunk size

The task spawns a subflow to perform parallel reduction over init and the elements in the range [first, last). The reduced result is store in init. The runtime partitions the range into chunks of size chunk_size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.

Returns
a Task handle

◆ reduce_guided()

template<typename B , typename E , typename T , typename O , typename H = size_t>
Task tf::FlowBuilder::reduce_guided ( B &&  first,
E &&  last,
T &  init,
O &&  bop,
H &&  chunk_size = 1 
)

constructs a STL-styled parallel-reduce task using the guided partition algorithm

Template Parameters
Bbeginning iterator type
Eending iterator type
Tresult type
Obinary reducer type
Hchunk size type
Parameters
firstiterator to the beginning (inclusive)
lastiterator to the end (exclusive)
initinitial value of the reduction and the storage for the reduced result
bopbinary operator that will be applied
chunk_sizechunk size

The task spawns a subflow to perform parallel reduction over init and the elements in the range [first, last). The reduced result is store in init. The runtime partitions the range into chunks of size chunk_size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.

Returns
a Task handle

◆ reduce_static()

template<typename B , typename E , typename T , typename O , typename H = size_t>
Task tf::FlowBuilder::reduce_static ( B &&  first,
E &&  last,
T &  init,
O &&  bop,
H &&  chunk_size = 0 
)

constructs a STL-styled parallel-reduce task using the static partition algorithm

Template Parameters
Bbeginning iterator type
Eending iterator type
Tresult type
Obinary reducer type
Hchunk size type
Parameters
firstiterator to the beginning (inclusive)
lastiterator to the end (exclusive)
initinitial value of the reduction and the storage for the reduced result
bopbinary operator that will be applied
chunk_sizechunk size

The task spawns a subflow to perform parallel reduction over init and the elements in the range [first, last). The reduced result is store in init. The runtime partitions the range into chunks of size chunk_size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.

Returns
a Task handle

◆ transform_reduce()

template<typename B , typename E , typename T , typename BOP , typename UOP >
Task tf::FlowBuilder::transform_reduce ( B &&  first,
E &&  last,
T &  init,
BOP &&  bop,
UOP &&  uop 
)

constructs a STL-styled parallel transform-reduce task

Template Parameters
Bbeginning iterator type
Eending iterator type
Tresult type
BOPbinary reducer type
UOPunary transformion type
Parameters
firstiterator to the beginning (inclusive)
lastiterator to the end (exclusive)
initinitial value of the reduction and the storage for the reduced result
bopbinary operator that will be applied in unspecified order to the results of uop
uopunary operator that will be applied to transform each element in the range to the result type
Returns
a Task handle

The task spawns a subflow to perform parallel reduction over init and the transformed elements in the range [first, last). The reduced result is store in init. The runtime partitions the range into chunks of the given chunk size, where each chunk is processed by a worker. By default, we employ the guided partition algorithm.

This method is equivalent to the parallel execution of the following loop:

for(auto itr=first; itr!=last; itr++) {
init = bop(init, uop(*itr));
}

Arguments are templated to enable stateful passing using std::reference_wrapper.

◆ transform_reduce_dynamic()

template<typename B , typename E , typename T , typename BOP , typename UOP , typename H = size_t>
Task tf::FlowBuilder::transform_reduce_dynamic ( B &&  first,
E &&  last,
T &  init,
BOP &&  bop,
UOP &&  uop,
H &&  chunk_size = 1 
)

constructs a STL-styled parallel transform-reduce task using the dynamic partition algorithm

Template Parameters
Bbeginning iterator type
Eending iterator type
Tresult type
BOPbinary reducer type
UOPunary transformion type
Hchunk size type
Parameters
firstiterator to the beginning (inclusive)
lastiterator to the end (exclusive)
initinitial value of the reduction and the storage for the reduced result
bopbinary operator that will be applied in unspecified order to the results of uop
uopunary operator that will be applied to transform each element in the range to the result type
chunk_sizechunk size
Returns
a Task handle

The task spawns a subflow to perform parallel reduction over init and the transformed elements in the range [first, last). The reduced result is store in init. The runtime partitions the range into chunks of size chunk_size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.

◆ transform_reduce_guided()

template<typename B , typename E , typename T , typename BOP , typename UOP , typename H = size_t>
Task tf::FlowBuilder::transform_reduce_guided ( B &&  first,
E &&  last,
T &  init,
BOP &&  bop,
UOP &&  uop,
H &&  chunk_size = 1 
)

constructs a STL-styled parallel transform-reduce task using the guided partition algorithm

Template Parameters
Bbeginning iterator type
Eending iterator type
Tresult type
BOPbinary reducer type
UOPunary transformion type
Hchunk size type
Parameters
firstiterator to the beginning (inclusive)
lastiterator to the end (exclusive)
initinitial value of the reduction and the storage for the reduced result
bopbinary operator that will be applied in unspecified order to the results of uop
uopunary operator that will be applied to transform each element in the range to the result type
chunk_sizechunk size
Returns
a Task handle

The task spawns a subflow to perform parallel reduction over init and the transformed elements in the range [first, last). The reduced result is store in init. The runtime partitions the range into chunks of size chunk_size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.

◆ transform_reduce_static()

template<typename B , typename E , typename T , typename BOP , typename UOP , typename H = size_t>
Task tf::FlowBuilder::transform_reduce_static ( B &&  first,
E &&  last,
T &  init,
BOP &&  bop,
UOP &&  uop,
H &&  chunk_size = 0 
)

constructs a STL-styled parallel transform-reduce task using the static partition algorithm

Template Parameters
Bbeginning iterator type
Eending iterator type
Tresult type
BOPbinary reducer type
UOPunary transformion type
Hchunk size type
Parameters
firstiterator to the beginning (inclusive)
lastiterator to the end (exclusive)
initinitial value of the reduction and the storage for the reduced result
bopbinary operator that will be applied in unspecified order to the results of uop
uopunary operator that will be applied to transform each element in the range to the result type
chunk_sizechunk size
Returns
a Task handle

The task spawns a subflow to perform parallel reduction over init and the transformed elements in the range [first, last). The reduced result is store in init. The runtime partitions the range into chunks of size chunk_size, where each chunk is processed by a worker.

Arguments are templated to enable stateful passing using std::reference_wrapper.


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