ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::FastFlowExecutor Class Reference

the executor on a ParallelFor of FastFlow More...

#include <ADS/parallel/FastFlowExecutor.h>

Public types

using lock_type = FastFlowLock
 the lock of the data shared by the workers of run()

Public member functions

 FastFlowExecutor (std::size_t p=0, bool spin=true)
 the executor of \( p \) workers of FastFlow (the hardware threads if \( p = 0 \)), which spin between the calls if spin
std::size_t concurrency (void) const
 the number of workers
template<class F>
void bulk (std::size_t n, F &&f)
 the calls \( f( 0 ) , \ldots , f( n - 1 ) \) on the workers, in order on the calling thread if it is inside a call
template<class F>
void run (std::size_t p, F &&f)
 the calls \( f( 0 ) , \ldots , f( p - 1 ) \) of long-lived workers, at the same time on \( p \) workers of FastFlow

Detailed description

the executor on a ParallelFor of FastFlow

Member typedef documentation

◆ lock_type

the lock of the data shared by the workers of run()

Constructor and destructor documentation

◆ FastFlowExecutor()

ADS::FastFlowExecutor::FastFlowExecutor ( std::size_t p = 0,
bool spin = true )
inlineexplicit

the executor of \( p \) workers of FastFlow (the hardware threads if \( p = 0 \)), which spin between the calls if spin

Precondition
\( p \ge 1 \) once the hardware threads are counted

Member function documentation

◆ bulk()

template<class F>
void ADS::FastFlowExecutor::bulk ( std::size_t n,
F && f )
inline

the calls \( f( 0 ) , \ldots , f( n - 1 ) \) on the workers, in order on the calling thread if it is inside a call

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{bulk}( n , f ) \cr 2 & \quad \textbf{if}\ n \le 1\ \textbf{or}\ p = 1\ \textbf{or} \ \text{inside a call of } f\ \textbf{then} \cr 3 & \qquad \textbf{for}\ i \gets 0\ \textbf{to}\ n - 1\ \textbf{do} \ f( i ) \cr 4 & \quad \textbf{else}\ \text{the } \mathrm{parallel\_for} \text{ of } \text{FastFlow on } [ 0 , \max\{ n , p \} ) \text{ in chunks of 1,} \cr & \qquad \text{on all the } p \text{ workers, the indices from } n \text{ doing nothing} \end{array}} \]

◆ concurrency()

std::size_t ADS::FastFlowExecutor::concurrency ( void ) const
inlinenodiscard

the number of workers

◆ run()

template<class F>
void ADS::FastFlowExecutor::run ( std::size_t p,
F && f )
inline

the calls \( f( 0 ) , \ldots , f( p - 1 ) \) of long-lived workers, at the same time on \( p \) workers of FastFlow

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{run}( p , f ) \cr 2 & \quad \textbf{if}\ p \le 1\ \textbf{or}\ \text{inside a call of } f\ \textbf{then}\ \textbf{for}\ i \gets 0\ \textbf{to}\ p - 1 \ \textbf{do}\ f( i );\ \textbf{return} \cr 3 & \quad \text{the } \mathrm{parallel\_for} \text{ of FastFlow on } [ 0 , p ) \text{ in chunks of 1, on } p \text{ workers, the worker } i \text{ first given } i \cr 4 & \quad \text{throw again the first exception of the calls, if any} \end{array}} \]

Precondition
\( p \le \) concurrency(); \( p \le 1 \) inside a call

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