STAPL API Reference          
Overview   Containers   Algorithms   Views   Skeletons   Run-Time System
Modules     Classes    
List of all members | Static Public Member Functions
stapl::runtime::concurrency Class Reference

Initializes and controls threads for shared-memory concurrency. More...

Static Public Member Functions

static void initialize (option const &opts, const process_id pid, const unsigned npids, const unsigned int nppn)
 Initializes the concurrency layer. More...
 
static void finalize (void)
 Finalizes the concurrency layer.
 
static unsigned int hardware_concurrency (void) noexcept
 Returns the total number of threads available to the runtime. More...
 
static std::thread::id get_master_thread_id (void) noexcept
 Returns the id of the master thread of this process.
 
static std::vector< unsigned int > get_level_widths (void)
 Returns the parallelism level widths.
 
static unsigned int available_levels (void) noexcept
 Returns the available parallelism levels. More...
 
static affinity_tag get_affinity (void) noexcept
 Returns the affinity of the calling thread.
 
static hierarchical_mutexget_mutex (void) noexcept
 Returns the hierarchical_mutex tied to the calling thread.
 
static void fork (std::function< void(unsigned int)> init, std::function< void(unsigned int)> f, const unsigned int n=1)
 Consumes the next n available parallelism levels and executes the given function on them. More...
 

Detailed Description

Initializes and controls threads for shared-memory concurrency.

Member Function Documentation

◆ initialize()

void stapl::runtime::concurrency::initialize ( option const &  opts,
const process_id  pid,
const unsigned  npids,
const unsigned int  nppn 
)
static

Initializes the concurrency layer.

The only option currently supported for the option object is STAPL_PROC_HIERARCHY that is a comma-separated value that describes the shared memory node hierarchy (e.g STAPL_PROC_HIERARCHY=2,4,2 means 2 sockets, with 4 cores each and 2 threads each).

Parameters
optsOptions to pass for initialization.
pidCurrent process id.
npidsTotal number of processes.
nppnNumber of processes per node.

◆ hardware_concurrency()

unsigned int stapl::runtime::concurrency::hardware_concurrency ( void  )
staticnoexcept

Returns the total number of threads available to the runtime.

Warning
This value is just a hint; there might be more or less threads in absolute value.

◆ available_levels()

unsigned int stapl::runtime::concurrency::available_levels ( void  )
staticnoexcept

Returns the available parallelism levels.

After each call of fork, the number of available levels decreases by n, where n is the last argument in fork.

◆ fork()

void stapl::runtime::concurrency::fork ( std::function< void(unsigned int)>  init,
std::function< void(unsigned int)>  f,
const unsigned int  n = 1 
)
static

Consumes the next n available parallelism levels and executes the given function on them.

n is either n or available_levels(), whichever is smaller. The init function is run from the main thread and is passed the size of the new parallel section while f is being passed each thread's id.

Parameters
initFunction to invoke only on the main thread.
fFunction to invoke on all threads in the new parallel section.
nNumber of parallelism levels to run f on.

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