Chapter 18. Parallel Mode

Table of Contents

Intro
Semantics
Using
Prerequisite Compiler Flags
Using Parallel Mode
Using Specific Parallel Components
Design
Interface Basics
Configuration and Tuning
Setting up the OpenMP Environment
Compile Time Switches
Run Time Settings and Defaults
Implementation Namespaces
Testing
Bibliography

The libstdc++ parallel mode is an experimental parallel implementation of many algorithms of the C++ Standard Library.

Several of the standard algorithms, for instance std::sort, are made parallel using OpenMP annotations. These parallel mode constructs can be invoked by explicit source declaration or by compiling existing sources with a specific compiler flag.

Note

The parallel mode has not been kept up to date with recent C++ standards and so it only conforms to the C++03 requirements. That means that move-only predicates may not work with parallel mode algorithms, and for C++20 most of the algorithms cannot be used in constexpr functions.

For C++17 and above there are new overloads of the standard algorithms which take an execution policy argument. You should consider using those instead of the non-standard parallel mode extensions.

Intro

The following library components in the include numeric are included in the parallel mode:

  • std::accumulate

  • std::adjacent_difference

  • std::inner_product

  • std::partial_sum

The following library components in the include algorithm are included in the parallel mode:

  • std::adjacent_find

  • std::count

  • std::count_if

  • std::equal

  • std::find

  • std::find_if

  • std::find_first_of

  • std::for_each

  • std::generate

  • std::generate_n

  • std::lexicographical_compare

  • std::mismatch

  • std::search

  • std::search_n

  • std::transform

  • std::replace

  • std::replace_if

  • std::max_element

  • std::merge

  • std::min_element

  • std::nth_element

  • std::partial_sort

  • std::partition

  • std::random_shuffle

  • std::set_union

  • std::set_intersection

  • std::set_symmetric_difference

  • std::set_difference

  • std::sort

  • std::stable_sort

  • std::unique_copy

Bibliography

Parallelization of Bulk Operations for STL Dictionaries . Johannes Singler. Leonor Frias. Copyright © 2007 . Workshop on Highly Parallel Processing on a Chip (HPPC) 2007. (LNCS) .

The Multi-Core Standard Template Library . Johannes Singler. Peter Sanders. Felix Putze. Copyright © 2007 . Euro-Par 2007: Parallel Processing. (LNCS 4641) .