MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::parallel::pool_local_noexc::detail Namespace Reference

Classes

struct  pool_config
 What configure() asked for, and whether the pool already exists. More...
struct  region_thread
 This thread's region state (#640). More...
class  region_scope
 Marks the scope of a region tid on a thread that is not a pool worker, and restores the state after, so a region nested in another leaves the outer one's state set. More...

Enumerations

enum  : unsigned char { outside_region = 0 , inside_region = 1 , pool_worker = 2 }

Functions

unsigned resolve_pool_spin (unsigned fallback)
 Spin iterations from MTL5_POOL_SPIN; fallback when unset or invalid: signed, out of range, empty or not all digits (env_unsigned, issue 876).
unsigned clamp_pool_threads (unsigned long v)
 Clamp a requested thread count to [1, hardware concurrency].
bool env_unsigned (const char *name, unsigned &out)
 Read environment variable name as a whole unsigned decimal: digits only, no sign, space or trailing characters, at most 0xFFFFFFFF.
unsigned resolve_pool_threads ()
 Resolve the pool size from MTL5_NUM_THREADS (clamped to hardware concurrency); 1 when unset/invalid (see env_unsigned).
pool_config & config ()
region_thread & this_region_thread () noexcept
bool in_region () noexcept
 True while this thread runs a tid of an MTL5 region (see the contract at the top of this header).
bool on_pool_worker () noexcept
 True on the pool's worker threads, which are inside a region whenever they run anything at all.
unsigned claim_pool_size ()
unsigned team_for (std::size_t n, std::size_t grain, unsigned max_threads, unsigned pool_size) noexcept
 Team for a chunked loop over n units on a pool of pool_size: the pool, or max_threads if that is smaller and nonzero, cut so each chunk holds >= grain units; 1 (serial) when the pool is serial or n < 2 * grain.
template<typename Pool, typename Body>
void chunked_for (Pool &pool, std::size_t n, std::size_t grain, unsigned max_threads, Body &&body)
 parallel_for on pool; see thread_pool::parallel_for.
template<typename T, typename Pool, typename MapFn>
T chunked_reduce (Pool &pool, std::size_t n, std::size_t grain, unsigned max_threads, MapFn &&map)
 parallel_reduce on pool; see thread_pool::parallel_reduce.
template<typename Acc, typename Pool, typename InitFn, typename MapFn, typename CombineFn>
Acc chunked_accumulate (Pool &pool, std::size_t n, std::size_t grain, unsigned max_threads, InitFn &&init, MapFn &&map, CombineFn &&combine)
 parallel_accumulate on pool; see thread_pool::parallel_accumulate.
void cpu_relax () noexcept
 One spin-wait iteration: a pause hint to the core, nothing else.
void spin_step (unsigned i) noexcept
 One iteration of a spin wait: a pause, and every 64th iteration a yield, so a thread the scheduler has queued on this core behind the spinner runs within a few microseconds instead of after the whole spin.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : unsigned char
Enumerator
outside_region 
inside_region 
pool_worker 

Function Documentation

◆ chunked_accumulate()

template<typename Acc, typename Pool, typename InitFn, typename MapFn, typename CombineFn>
Acc mtl::parallel::pool_local_noexc::detail::chunked_accumulate ( Pool & pool,
std::size_t n,
std::size_t grain,
unsigned max_threads,
InitFn && init,
MapFn && map,
CombineFn && combine )

parallel_accumulate on pool; see thread_pool::parallel_accumulate.

◆ chunked_for()

template<typename Pool, typename Body>
void mtl::parallel::pool_local_noexc::detail::chunked_for ( Pool & pool,
std::size_t n,
std::size_t grain,
unsigned max_threads,
Body && body )

parallel_for on pool; see thread_pool::parallel_for.

◆ chunked_reduce()

template<typename T, typename Pool, typename MapFn>
T mtl::parallel::pool_local_noexc::detail::chunked_reduce ( Pool & pool,
std::size_t n,
std::size_t grain,
unsigned max_threads,
MapFn && map )

parallel_reduce on pool; see thread_pool::parallel_reduce.

◆ claim_pool_size()

unsigned mtl::parallel::pool_local_noexc::detail::claim_pool_size ( )
inline

◆ clamp_pool_threads()

unsigned mtl::parallel::pool_local_noexc::detail::clamp_pool_threads ( unsigned long v)
inline

Clamp a requested thread count to [1, hardware concurrency].

◆ config()

pool_config & mtl::parallel::pool_local_noexc::detail::config ( )
inline

◆ cpu_relax()

void mtl::parallel::pool_local_noexc::detail::cpu_relax ( )
inlinenoexcept

One spin-wait iteration: a pause hint to the core, nothing else.

◆ env_unsigned()

bool mtl::parallel::pool_local_noexc::detail::env_unsigned ( const char * name,
unsigned & out )
inline

Read environment variable name as a whole unsigned decimal: digits only, no sign, space or trailing characters, at most 0xFFFFFFFF.

False when it is unset or not such a number. strtoul, which both pool variables used, accepts a leading '-' and wraps: MTL5_POOL_SPIN=-1 became the largest spin, 4294967295 iterations (issue 876).

◆ in_region()

bool mtl::parallel::pool_local_noexc::detail::in_region ( )
inlinenoexcept

True while this thread runs a tid of an MTL5 region (see the contract at the top of this header).

An external library that runs a thread team of its own runs it on one thread here: MTL5 already occupies the cores.

◆ on_pool_worker()

bool mtl::parallel::pool_local_noexc::detail::on_pool_worker ( )
inlinenoexcept

True on the pool's worker threads, which are inside a region whenever they run anything at all.

◆ resolve_pool_spin()

unsigned mtl::parallel::pool_local_noexc::detail::resolve_pool_spin ( unsigned fallback)
inline

Spin iterations from MTL5_POOL_SPIN; fallback when unset or invalid: signed, out of range, empty or not all digits (env_unsigned, issue 876).

"-1" and values past 2^32 used to give the largest spin.

◆ resolve_pool_threads()

unsigned mtl::parallel::pool_local_noexc::detail::resolve_pool_threads ( )
inline

Resolve the pool size from MTL5_NUM_THREADS (clamped to hardware concurrency); 1 when unset/invalid (see env_unsigned).

◆ spin_step()

void mtl::parallel::pool_local_noexc::detail::spin_step ( unsigned i)
inlinenoexcept

One iteration of a spin wait: a pause, and every 64th iteration a yield, so a thread the scheduler has queued on this core behind the spinner runs within a few microseconds instead of after the whole spin.

◆ team_for()

unsigned mtl::parallel::pool_local_noexc::detail::team_for ( std::size_t n,
std::size_t grain,
unsigned max_threads,
unsigned pool_size )
inlinenoexcept

Team for a chunked loop over n units on a pool of pool_size: the pool, or max_threads if that is smaller and nonzero, cut so each chunk holds >= grain units; 1 (serial) when the pool is serial or n < 2 * grain.

◆ this_region_thread()

region_thread & mtl::parallel::pool_local_noexc::detail::this_region_thread ( )
inlinenoexcept