![]() |
Taskflow
3.2.0-Master-Branch
|
class to create a scalable pipeline object More...
#include <pipeline.hpp>
Public Types | |
using | pipe_type = typename std::iterator_traits< P >::value_type |
pipe type | |
Public Member Functions | |
ScalablePipeline ()=default | |
default constructor | |
ScalablePipeline (size_t num_lines) | |
constructs an empty scalable pipeline object | |
ScalablePipeline (size_t num_lines, P first, P last) | |
constructs a scalable pipeline object | |
ScalablePipeline (const ScalablePipeline &)=delete | |
disabled copy constructor | |
ScalablePipeline (ScalablePipeline &&rhs) | |
move constructor | |
ScalablePipeline & | operator= (const ScalablePipeline &)=delete |
disabled copy assignment operator | |
ScalablePipeline & | operator= (ScalablePipeline &&rhs) |
move constructor | |
size_t | num_lines () const noexcept |
queries the number of parallel lines | |
size_t | num_pipes () const noexcept |
queries the number of pipes | |
void | reset () |
resets the pipeline | |
void | reset (P first, P last) |
resets the pipeline with a new range of pipes | |
void | reset (size_t num_lines, P first, P last) |
resets the pipeline to a new line number and a new range of pipes | |
size_t | num_tokens () const noexcept |
queries the number of generated tokens in the pipeline | |
Graph & | graph () |
obtains the graph object associated with the pipeline construct | |
class to create a scalable pipeline object
P | type of the iterator to a range of pipes |
A scalable pipeline is a composable graph object for users to create a pipeline scheduling framework using a module task in a taskflow. Unlike tf::Pipeline that instantiates all pipes upon the construction time, tf::ScalablePipeline allows variable assignments of pipes using range iterators. Users can also reset a scalable pipeline to a different range of pipes between runs. The following code creates a scalable pipeline of four parallel lines to schedule tokens through three serial pipes in a custom storage, then resetting the pipeline to a new range of five serial pipes:
The above example creates a pipeline graph that schedules five tokens over four parallel lines in a circular fashion, first going through three serial pipes and then five serial pipes:
Each pipe has the same type of tf::Pipe<std::function<void(tf::Pipeflow&)>>
and is kept in a vector that is amenable to change. We construct the scalable pipeline using two range iterators pointing to the beginning and the end of the vector. At each pipe stage, the program propagates the result to the next pipe by adding one to the result stored in a custom data storage, buffer
. The pipeline scheduler will generate five scheduling tokens and then stop.
A scalable pipeline is move-only.
tf::ScalablePipeline< P >::ScalablePipeline | ( | size_t | num_lines | ) |
constructs an empty scalable pipeline object
num_lines | the number of parallel lines |
An empty scalable pipeline does not have any pipes. The pipeline needs to be reset to a valid range of pipes before running.
tf::ScalablePipeline< P >::ScalablePipeline | ( | size_t | num_lines, |
P | first, | ||
P | last | ||
) |
constructs a scalable pipeline object
num_lines | the number of parallel lines |
first | iterator to the beginning of the range |
last | iterator to the end of the range |
Constructs a pipeline from the given range of pipes specified in [first, last)
using num_lines
parallel lines. The first pipe must define a serial direction (tf::PipeType::SERIAL) or an exception will be thrown.
Internally, the scalable pipeline copies the iterators from the specified range. Those pipe callables pointed to by these iterators must remain valid during the execution of the pipeline.
tf::ScalablePipeline< P >::ScalablePipeline | ( | ScalablePipeline< P > && | rhs | ) |
move constructor
Constructs a pipeline from the given rhs
using move semantics (i.e. the data in rhs
is moved into this pipeline). After the move, rhs
is in a state as if it is just constructed. The behavior is undefined if rhs
is running during the move.
Graph & tf::ScalablePipeline< P >::graph | ( | ) |
obtains the graph object associated with the pipeline construct
This method is primarily used as an opaque data structure for creating a module task of the this pipeline.
|
noexcept |
queries the number of parallel lines
The function returns the number of parallel lines given by the user upon the construction of the pipeline. The number of lines represents the maximum parallelism this pipeline can achieve.
|
noexcept |
queries the number of pipes
The Function returns the number of pipes given by the user upon the construction of the pipeline.
|
noexcept |
queries the number of generated tokens in the pipeline
The number represents the total scheduling tokens that has been generated by the pipeline so far.
ScalablePipeline< P > & tf::ScalablePipeline< P >::operator= | ( | ScalablePipeline< P > && | rhs | ) |
move constructor
Replaces the contents with those of rhs
using move semantics (i.e. the data in rhs
is moved into this pipeline). After the move, rhs
is in a state as if it is just constructed. The behavior is undefined if rhs
is running during the move.
void tf::ScalablePipeline< P >::reset | ( | ) |
resets the pipeline
Resets the pipeline to the initial state. After resetting a pipeline, its token identifier will start from zero.
void tf::ScalablePipeline< P >::reset | ( | P | first, |
P | last | ||
) |
resets the pipeline with a new range of pipes
first | iterator to the beginning of the range |
last | iterator to the end of the range |
The member function assigns the pipeline to a new range of pipes specified in [first, last)
and resets the pipeline to the initial state. After resetting a pipeline, its token identifier will start from zero.
Internally, the scalable pipeline copies the iterators from the specified range. Those pipe callables pointed to by these iterators must remain valid during the execution of the pipeline.
void tf::ScalablePipeline< P >::reset | ( | size_t | num_lines, |
P | first, | ||
P | last | ||
) |
resets the pipeline to a new line number and a new range of pipes
num_lines | number of parallel lines |
first | iterator to the beginning of the range |
last | iterator to the end of the range |
The member function resets the pipeline to a new number of parallel lines and a new range of pipes specified in [first, last)
, as if the pipeline is just constructed. After resetting a pipeline, its token identifier will start from zero.
Internally, the scalable pipeline copies the iterators from the specified range. Those pipe callables pointed to by these iterators must remain valid during the execution of the pipeline.