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 () |
|
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.
|
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().
|
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().
|
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.
|
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.
|
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().
|
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.