Loading...
Searching...
No Matches
q3::execution::threading Namespace Reference

Functions

constexpr bool is_compiled_with_openmp ()
 
bool is_inside_parallel_region ()
 
int maximum_threads ()
 
void slice_bounds (long long work_items, int number_of_slices, int slice_index, long long &first, long long &last)
 
int team_size ()
 
int thread_count_for (long long work_items, long long minimum_items_per_thread)
 
int thread_index ()
 

Function Documentation

◆ is_compiled_with_openmp()

constexpr bool q3::execution::threading::is_compiled_with_openmp ( )
inlineconstexpr

Whether this translation unit was compiled with OpenMP enabled.

Reported in the run header so a log says which binary produced it, and used by tests that assert the single-thread path is taken either way.

Definition at line 40 of file threading.hpp.

◆ is_inside_parallel_region()

bool q3::execution::threading::is_inside_parallel_region ( )
inline

Whether the caller is already inside a parallel region.

Hot loops nest – the band loop in the Hamiltonian applicator contains the scatter/gather loops – and an inner region that forked its own team would oversubscribe the machine. Inner call sites gate on this and stay serial when an outer region has already claimed the cores.

Definition at line 99 of file threading.hpp.

Referenced by thread_count_for().

◆ maximum_threads()

int q3::execution::threading::maximum_threads ( )
inline

The largest team a parallel region could be given here, which is what OMP_NUM_THREADS sets. Always 1 without OpenMP.

Definition at line 52 of file threading.hpp.

Referenced by q3::execution::PlanewaveExecutionPolicy::execution_record(), q3::SerialFFTGrid::init(), q3::new_results(), q3::PlanewaveKohnShamSCFReporter::report_setup_summary(), and thread_count_for().

◆ slice_bounds()

void q3::execution::threading::slice_bounds ( long long  work_items,
int  number_of_slices,
int  slice_index,
long long &  first,
long long &  last 
)
inline

The half-open slice of [0, work_items) that slice_index of number_of_slices owns, written into first and last.

Deterministic and independent of how the slices are then scheduled, which is what lets a threaded reduction stay bit-identical: a thread always sums the same contiguous run of terms in the same order, and the partial sums are combined by slice index afterwards. The first work_items % number_of_slices slices take one extra item.

Definition at line 142 of file threading.hpp.

◆ team_size()

int q3::execution::threading::team_size ( )
inline

The size of the team actually running the enclosing parallel region, or 1 outside one.

num_threads(n) is a request, not a promise – a runtime with dynamic adjustment on may hand back a smaller team. Code that splits an array into one slice per thread must divide by the team it got, not the team it asked for, or the slices at the end belong to threads that never ran and the work is silently skipped.

Definition at line 83 of file threading.hpp.

◆ thread_count_for()

int q3::execution::threading::thread_count_for ( long long  work_items,
long long  minimum_items_per_thread 
)
inline

How many threads to ask for over work_items, given that a thread is not worth starting until it has minimum_items_per_thread of work to do.

Returns 1 – meaning "run this region serially, do not fork" – when OpenMP is off, when OMP_NUM_THREADS is 1, when an outer region already holds the cores, or when the loop is too short to pay for a team. Never returns more than maximum_threads().

Definition at line 116 of file threading.hpp.

References is_inside_parallel_region(), and maximum_threads().

◆ thread_index()

int q3::execution::threading::thread_index ( )
inline

The calling thread's index inside the enclosing parallel region, or 0 when there is none. Used to pick a per-thread scratch slot, which is also why it must stay a plain index into a dense range rather than an opaque id.

Definition at line 65 of file threading.hpp.