# settings.h File Reference

## Detailed Description

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.

## parallelization_decision

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.

      std::sort(v.begin(), v.end(), __gnu_parallel::sequential_tag());

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.

Go to the source code of this file.

## Namespaces

- namespace __gnu_parallel

## Classes

- struct __gnu_parallel::_Settings
    Run-time settings for the parallel mode, including all tunable parameters. More...

## Defines

- #define _GLIBCXX_PARALLEL_CONDITION(c)
- #define _GLIBCXX_PARALLEL_SETTINGS_H

## Define Documentation

#define _GLIBCXX_PARALLEL_CONDITION | ( | c |  | ) |

Determine at compile(?)-time if the parallel variant of an algorithm should be called.

Parameters:

  | c | A condition that is convertible to bool that is overruled by __gnu_parallel::_Settings::algorithm_strategy. Usually a decision based on the input size.

Definition at line 101 of file settings.h.

Referenced by std::__parallel::accumulate_switch(), std::__parallel::adjacent_difference_switch(), std::__parallel::adjacent_find_switch(), std::__parallel::count_if_switch(), std::__parallel::count_switch(), std::__parallel::find_if_switch(), std::__parallel::find_switch(), std::__parallel::for_each_switch(), std::__parallel::generate_switch(), std::__parallel::inner_product_switch(), std::__parallel::lexicographical_compare_switch(), std::__parallel::max_element_switch(), std::__parallel::merge_switch(), std::__parallel::min_element_switch(), std::__parallel::mismatch_switch(), __gnu_parallel::multiway_merge(), __gnu_parallel::multiway_merge_sentinel(), std::__parallel::nth_element(), std::__parallel::partial_sort(), std::__parallel::partial_sum_switch(), std::__parallel::partition_switch(), std::__parallel::random_shuffle(), std::__parallel::replace_if_switch(), std::__parallel::search_n_switch(), std::__parallel::search_switch(), std::__parallel::set_difference_switch(), std::__parallel::set_intersection_switch(), std::__parallel::set_symmetric_difference_switch(), std::__parallel::set_union_switch(), std::__parallel::sort(), std::__parallel::stable_sort(), std::__parallel::transform1_switch(), std::__parallel::transform2_switch(), and std::__parallel::unique_copy_switch().