The latest version of this document is always available at http://gcc.gnu.org/onlinedocs/libstdc++/parallel_mode.html.
To the libstdc++-v3 homepage.
The libstdc++ parallel mode is an experimental parallel implementation of many algorithms the C++ Standard Library.
Several of the standard algorithms, for instance
std::search, are made parallel using OpenMP
annotations. These parallel mode constructs and can be invoked by
explicit source declaration or by compiling existing sources with a
specific compiler flag.
The libstdc++ parallel mode performs parallization of algorithms, function objects, classes, and functions in the C++ Standard.
To use the libstdc++ parallel mode, compile your application with
the compiler flag -D_GLIBCXX_PARALLEL -fopenmp. This
will link in libgomp, the GNU OpenMP implementation,
whose presence is mandatory. In addition, hardware capable of atomic
operations is de rigueur. Actually activating these atomic
operations may require explicit compiler flags on some targets
(like sparc and x86), such as -march=i686,
-march=native or -mcpu=v9.
Note that the _GLIBCXX_PARALLEL define may change the
sizes and behavior of standard class templates such as
std::search, and therefore one can only link code
compiled with parallel mode and code compiled without parallel mode
if no instantiation of a container is passed between the two
translation units. Parallel mode functionality has distinct linkage,
and cannot be confused with normal mode symbols.
The following library components in the include
<numeric> are included in the parallel mode:
std::accumulatestd::adjacent_differencestd::inner_productstd::partial_sumThe following library components in the include
<algorithm> are included in the parallel mode:
std::adjacent_findstd::countstd::count_ifstd::equalstd::findstd::find_ifstd::find_first_ofstd::for_eachstd::generatestd::generate_nstd::lexicographical_comparestd::mismatchstd::searchstd::search_nstd::transformstd::replacestd::replace_ifstd::max_elementstd::mergestd::min_elementstd::nth_elementstd::partial_sortstd::partitionstd::random_shufflestd::set_unionstd::set_intersectionstd::set_symmetric_differencestd::set_differencestd::sortstd::stable_sortstd::unique_copyWhen it is not feasible to recompile your entire application, or only specific algorithms need to be parallel-aware, individual parallel algorithms can be made available explicitly. These parallel algorithms are functionally equivalent to the standard drop-in algorithms used in parallel mode, but they are available in a separate namespace as GNU extensions and may be used in programs compiled with either release mode or with parallel mode. The following table provides the names and headers of the parallel algorithms:
| Algorithm | Header | Parallel algorithm | Parallel header |
|---|---|---|---|
| std::accumulate | <numeric> | __gnu_parallel::accumulate | <parallel/numeric> |
| std::adjacent_difference | <numeric> | __gnu_parallel::adjacent_difference | <parallel/numeric> |
| std::inner_product | <numeric> | __gnu_parallel::inner_product | <parallel/numeric> |
| std::partial_sum | <numeric> | __gnu_parallel::partial_sum | <parallel/numeric> |
| std::adjacent_find | <algorithm> | __gnu_parallel::adjacent_find | <parallel/algorithm> |
| std::count | <algorithm> | __gnu_parallel::count | <parallel/algorithm> |
| std::count_if | <algorithm> | __gnu_parallel::count_if | <parallel/algorithm> |
| std::equal | <algorithm> | __gnu_parallel::equal | <parallel/algorithm> |
| std::find | <algorithm> | __gnu_parallel::find | <parallel/algorithm> |
| std::find_if | <algorithm> | __gnu_parallel::find_if | <parallel/algorithm> |
| std::find_first_of | <algorithm> | __gnu_parallel::find_first_of | <parallel/algorithm> |
| std::for_each | <algorithm> | __gnu_parallel::for_each | <parallel/algorithm> |
| std::generate | <algorithm> | __gnu_parallel::generate | <parallel/algorithm> |
| std::generate_n | <algorithm> | __gnu_parallel::generate_n | <parallel/algorithm> |
| std::lexicographical_compare | <algorithm> | __gnu_parallel::lexicographical_compare | <parallel/algorithm> |
| std::mismatch | <algorithm> | __gnu_parallel::mismatch | <parallel/algorithm> |
| std::search | <algorithm> | __gnu_parallel::search | <parallel/algorithm> |
| std::search_n | <algorithm> | __gnu_parallel::search_n | <parallel/algorithm> |
| std::transform | <algorithm> | __gnu_parallel::transform | <parallel/algorithm> |
| std::replace | <algorithm> | __gnu_parallel::replace | <parallel/algorithm> |
| std::replace_if | <algorithm> | __gnu_parallel::replace_if | <parallel/algorithm> |
| std::max_element | <algorithm> | __gnu_parallel::max_element | <parallel/algorithm> |
| std::merge | <algorithm> | __gnu_parallel::merge | <parallel/algorithm> |
| std::min_element | <algorithm> | __gnu_parallel::min_element | <parallel/algorithm> |
| std::nth_element | <algorithm> | __gnu_parallel::nth_element | <parallel/algorithm> |
| std::partial_sort | <algorithm> | __gnu_parallel::partial_sort | <parallel/algorithm> |
| std::partition | <algorithm> | __gnu_parallel::partition | <parallel/algorithm> |
| std::random_shuffle | <algorithm> | __gnu_parallel::random_shuffle | <parallel/algorithm> |
| std::set_union | <algorithm> | __gnu_parallel::set_union | <parallel/algorithm> |
| std::set_intersection | <algorithm> | __gnu_parallel::set_intersection | <parallel/algorithm> |
| std::set_symmetric_difference | <algorithm> | __gnu_parallel::set_symmetric_difference | <parallel/algorithm> |
| std::set_difference | <algorithm> | __gnu_parallel::set_difference | <parallel/algorithm> |
| std::sort | <algorithm> | __gnu_parallel::sort | <parallel/algorithm> |
| std::stable_sort | <algorithm> | __gnu_parallel::stable_sort | <parallel/algorithm> |
| std::unique_copy | <algorithm> | __gnu_parallel::unique_copy | <parallel/algorithm> |
Something about exception safety, interaction with threads, etc. Goal is to have the usual constraints of the STL with respect to exception safety and threads, but add in support for parallel computing.
Something about compile-time settings and configuration, ie using
__gnu_parallel::Settings. XXX Up in the air.
Two namespaces contain the parallel mode:
std::__parallel and __gnu_parallel.
One namespace contain versions of code that are explicitly sequential:
__gnu_serial.
Parallel implementations of the sequential standard components are
defined in namespace std::__parallel. For instance,
std::transform from <algorithm> has a parallel
counterpart in std::__parallel::transform from
<parallel/algorithm>. In addition, these parallel
implementatations are injected into namespace
__gnu_parallel with using declarations.
Support and infrastructure is in namespace __gnu_parallel.
More information, and an organized index of types and functions related to the parallel mode on a per-namespace basis, can be found in the generated source documentation.
Both the normal conformance and regression tests and the supplemental performance tests work.
To run the conformance and regression tests with the parallel mode active,
make check-parallel
The log and summary files for conformance testing are in the
testsuite/parallel directory.
To run the performance tests with the parallel mode active,
make check-performance-parallel
The result file for performance testing are in the
testsuite directory, in the file
libstdc++_performance.sum. In addition, the policy-based
containers have their own visualizations, which have additional
software dependencies than the usual bare-boned text file, and can be
generated by using the make doc-performance rule in the
testsuite's Makefile.
Return to the top of the page or to the libstdc++ homepage.
See license.html for copying conditions. Comments and suggestions are welcome, and may be sent to the libstdc++ mailing list.