Runtime settings and tuning parameters, heuristics to decide whether to use parallelized algorithms. This file is a GNU parallel extension to the Standard C++ Library.
The decision whether to run an algorithm in parallel.
There are several ways the user can switch on and __off the parallel execution of an algorithm, both at compile- and run-time.
Only sequential execution can be forced at compile-time. This reduces code size and protects code parts that have non-thread-safe side effects.
Ultimately, forcing parallel execution at compile-time makes sense. Often, the sequential algorithm implementation is used as a subroutine, so no reduction in code size can be achieved. Also, the machine the program is run on might have only one processor core, so to avoid overhead, the algorithm is executed sequentially.
To force sequential execution of an algorithm ultimately at compile-time, the user must add the tag gnu_parallel::sequential_tag() to the end of the parameter list, e. g.
This is compatible with all overloaded algorithm variants. No additional code will be instantiated, at all. The same holds for most algorithm calls with iterators not providing random access.
If the algorithm call is not forced to be executed sequentially at compile-time, the decision is made at run-time. The global variable __gnu_parallel::_Settings::algorithm_strategy is checked. _It is a tristate variable corresponding to:
a. force_sequential, meaning the sequential algorithm is executed. b. force_parallel, meaning the parallel algorithm is executed. c. heuristic
For heuristic, the parallel algorithm implementation is called only if the input size is sufficiently large. For most algorithms, the input size is the (combined) length of the input sequence(__s). The threshold can be set by the user, individually for each algorithm. The according variables are called gnu_parallel::_Settings::[algorithm]_minimal_n .
For some of the algorithms, there are even more tuning options, e. g. the ability to choose from multiple algorithm variants. See below for details.
Definition in file settings.h.