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

the executor on the threads of OpenMP More...

#include <ADS/parallel/OpenMPExecutor.h>

Public types

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

Public member functions

 OpenMPExecutor (std::size_t p=0)
 the executor of \( p \) threads of OpenMP (omp_get_max_threads() if \( p = 0 \), or the team of the caller inside a region)
std::size_t concurrency (void) const
 the number of threads: \( p \), or, if \( p = 0 \), the threads of the team of the caller inside a region and omp_get_max_threads() outside
template<class F>
void bulk (std::size_t n, F &&f)
 the calls \( f( 0 ) , \ldots , f( n - 1 ) \) on the threads
template<class F, class G>
void invoke (F &&f, G &&g)
 the calls f() and g() in parallel, by bulk() on 2 indices
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 the \( p \) threads of a region of OpenMP

Detailed description

the executor on the threads of OpenMP

Member typedef documentation

◆ lock_type

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

Constructor and destructor documentation

◆ OpenMPExecutor()

ADS::OpenMPExecutor::OpenMPExecutor ( std::size_t p = 0)
inlineexplicit

the executor of \( p \) threads of OpenMP (omp_get_max_threads() if \( p = 0 \), or the team of the caller inside a region)

Precondition
\( p \ge 1 \)

Member function documentation

◆ bulk()

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

the calls \( f( 0 ) , \ldots , f( n - 1 ) \) on the threads

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{then} \ \textbf{for}\ i \gets 0\ \textbf{to}\ n - 1\ \textbf{do}\ f( i ) \cr 3 & \quad \textbf{else if}\ \text{in a parallel region}\ \textbf{then} \ \text{a } \mathrm{omp\ taskloop} \text{ on } [ 0 , n ) \text{ of chunks of 1, tasks of the team} \cr 4 & \quad \textbf{else}\ \text{a loop } \mathrm{omp\ parallel\ for} \text{ on } [ 0 , n ) \text{ of dynamic chunks of 1, on } \min\{ p , n \} \text{ threads} \end{array}} \]

◆ concurrency()

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

the number of threads: \( p \), or, if \( p = 0 \), the threads of the team of the caller inside a region and omp_get_max_threads() outside

◆ invoke()

template<class F, class G>
void ADS::OpenMPExecutor::invoke ( F && f,
G && g )
inline

the calls f() and g() in parallel, by bulk() on 2 indices

◆ run()

template<class F>
void ADS::OpenMPExecutor::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 the \( p \) threads of a region of OpenMP

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{then}\ \textbf{for}\ i \gets 0 \ \textbf{to}\ p - 1\ \textbf{do}\ f( i );\ \textbf{return} \cr 3 & \quad \text{a region } \mathrm{omp\ parallel} \text{ of } p \text{ threads, in which} \cr 4 & \qquad \textbf{if}\ \text{the team has } p \text{ threads} \ \textbf{then}\ f( \text{the number of the thread} ) \cr 5 & \quad \text{throw if the team was smaller, else throw again the } \text{first exception of the calls, if any} \end{array}} \]

Precondition
\( p \le \) concurrency()

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