Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/experimental/parallelism"

From cppreference.com
m (link to the right std::remove)
m (fmt, {{sup}})
 
(10 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
{{cpp/experimental/parallelism/navbar}}
 
{{cpp/experimental/parallelism/navbar}}
  
The C++ Extensions for Parallelism, ISO/IEC TS 19570:xxxx,<!-- looks like it will be 2015 at this point --> defines the following new components for the C++ standard library:
+
{{fmbox|class=noprint|style=font-size: 0.8em|text='''Merged into ISO C++''' The functionality described on this page was merged into the mainline ISO C++ standard (except for dynamic execution policy and {{tt|exception_list}}) as of 3/2016; see [[cpp/algorithm|the algorithm library]] {{mark since c++17}}}}
 +
 
 +
The C++ Extensions for Parallelism, ISO/IEC TS 19570:2015 defines the following new components for the C++ standard library:
  
 
===Execution policies===
 
===Execution policies===
<!-- Probably want to separate description of the actual execution policies from the meow_execution_policy classes -->
+
The parallelism TS describes three execution policies: [[cpp/experimental/parallelism/execution policy#sequential|sequential]], [[cpp/experimental/parallelism/execution policy#parallel|parallel]], and [[cpp/experimental/parallelism/execution policy#parallel vector|parallel+vector]], and provides corresponding execution policy types and objects. Users may select an execution policy statically by invoking a parallel algorithm with the an execution policy object of the corresponding type, or dynamically by using the type-erasing {{tt|execution_policy}} class.
 +
 
 +
Implementations may define additional execution policies as an extension. The semantics of parallel algorithms invoked with an execution policy object of implementation-defined type is implementation-defined.
  
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc header | experimental/execution_policy }}
+
{{dsc header|experimental/execution_policy}}
{{dsc class | cpp/experimental/sequential_execution_policy | sequential execution policy}}
+
{{dsc class|cpp/experimental/execution_policy_tag_t|title=sequential_execution_policy<br/>parallel_execution_policy<br/>parallel_vector_execution_policy|execution policy types}}
<!-- include seq as helper inside -->
+
{{dsc const|cpp/experimental/execution_policy_tag|title=seq<br/>par<br/>par_vec|global execution policy objects}}
{{dsc class | cpp/experimental/parallel_execution_policy | parallel execution policy}}
+
{{dsc class|cpp/experimental/execution_policy|dynamic execution policy}}
<!-- include par as helper inside -->
+
{{dsc tclass|cpp/experimental/is_execution_policy|test whether a class represents an execution policy}}
{{dsc class | cpp/experimental/parallel_vector_execution_policy | parallel/vector execution policy}}
+
<!-- include parvec as helper inside -->
+
{{dsc class | cpp/experimental/execution_policy | dynamic execution policy}}
+
{{dsc tclass | cpp/experimental/is_execution_policy | test whether a class represents an execution policy}}
+
 
{{dsc end}}
 
{{dsc end}}
  
=== Exception lists ===
+
===Exception lists===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc header | experimental/exception_list }}
+
{{dsc header|experimental/exception_list}}
{{dsc class | cpp/experimental/exception_list | exceptions raised during parallel executions}}
+
{{dsc class|cpp/experimental/exception_list|exceptions raised during parallel executions}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Parallelized versions of existing algorithms===
 
===Parallelized versions of existing algorithms===
Provides parallelized versions of 69 algorithms from <algorithm>, <numeric> and <memory>:
+
The TS provides [[cpp/experimental/parallelism/existing|parallelized versions]] of the following 69 algorithms from <algorithm>, <numeric> and <memory>:
<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
+
{{collapse top|Standard library algorithms for which parallelized versions are provided}}
 +
{{div col|3}}
 
* {{lc|std::adjacent_difference}}
 
* {{lc|std::adjacent_difference}}
 
* {{lc|std::adjacent_find}}
 
* {{lc|std::adjacent_find}}
Line 61: Line 62:
 
* {{lc|std::minmax_element}}
 
* {{lc|std::minmax_element}}
 
* {{lc|std::mismatch}}
 
* {{lc|std::mismatch}}
* {{lc|std::move}}
+
* {{ltt|cpp/algorithm/move|std::move}}
 
* {{lc|std::none_of}}
 
* {{lc|std::none_of}}
 
* {{lc|std::nth_element}}
 
* {{lc|std::nth_element}}
Line 97: Line 98:
 
* {{lc|std::unique}}
 
* {{lc|std::unique}}
 
* {{lc|std::unique_copy}}
 
* {{lc|std::unique_copy}}
</div>
+
{{div col end}}
Each parallelized algorithm:
+
{{collapse bottom}}
* is declared in the {{tt|std::experimental::parallel}} namespace; <!-- technically, it's in parallel::v1, but we ignore the inline namespace for other purposes too -->
+
* compared to the original algorithm, has an additional template parameter named {{tt|ExecutionPolicy}}, which is the first template parameter;
+
* compared to the original algorithm, has an additional function parameter of type {{tt|ExecutionPolicy&&}}, which is the first function parameter;
+
* does not participate in overload resolution unless {{c|is_execution_policy<std::decay_t<ExecutionPolicy>>::value}} is {{tt|true}};
+
* has semantics that is identical to the original algorithm.
+
  
 
===New algorithms===
 
===New algorithms===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc header | experimental/algorithm }}
+
{{dsc header|experimental/algorithm}}
{{dsc tfun | cpp/experimental/for_each | similar to {{lc|std::for_each}} except returns void}}
+
{{dsc tfun|cpp/experimental/for_each|similar to {{lc|std::for_each}} except returns void}}
{{dsc tfun | cpp/experimental/for_each_n | applies a function object to the first n elements of a sequence }}
+
{{dsc tfun|cpp/experimental/for_each_n|applies a function object to the first n elements of a sequence}}
{{dsc header | experimental/numeric }}
+
{{dsc header|experimental/numeric}}
{{dsc tfun | cpp/experimental/reduce | similar to {{lc|std::accumulate}}, except out of order }}
+
{{dsc inc|cpp/experimental/parallelism/dsc reduce}}
{{dsc tfun | cpp/experimental/exclusive_scan | similar to {{lc|std::partial_sum}}, excludes the ith input element from the ith sum}}
+
{{dsc tfun|cpp/experimental/exclusive_scan|similar to {{lc|std::partial_sum}}, excludes the i{{sup|th}} input element from the i{{sup|th}} sum}}
{{dsc tfun | cpp/experimental/inclusive_scan | similar to {{lc|std::partial_sum}}, includes the ith input element in the ith sum}}
+
{{dsc tfun|cpp/experimental/inclusive_scan|similar to {{lc|std::partial_sum}}, includes the i{{sup|th}} input element in the i{{sup|th}} sum}}
{{dsc tfun | cpp/experimental/transform_reduce | applies a functor, then reduces}}
+
{{dsc inc|cpp/experimental/parallelism/dsc transform_reduce}}
{{dsc tfun | cpp/experimental/transform_exclusive_scan | applies a functor, then calculates exclusive scan }}
+
{{dsc tfun|cpp/experimental/transform_exclusive_scan|applies a functor, then calculates exclusive scan}}
{{dsc tfun | cpp/experimental/transform_inclusive_scan | applies a functor, then calculates inclusive scan}}
+
{{dsc tfun|cpp/experimental/transform_inclusive_scan|applies a functor, then calculates inclusive scan}}
 
{{dsc end}}
 
{{dsc end}}
 +
 +
{{langlinks|zh}}

Latest revision as of 02:11, 28 November 2023

 
 
Experimental
Technical Specification
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
Experimental Non-TS
Pattern Matching
Linear Algebra
std::execution
Contracts
2D Graphics
 
 

The C++ Extensions for Parallelism, ISO/IEC TS 19570:2015 defines the following new components for the C++ standard library:

Contents

[edit] Execution policies

The parallelism TS describes three execution policies: sequential, parallel, and parallel+vector, and provides corresponding execution policy types and objects. Users may select an execution policy statically by invoking a parallel algorithm with the an execution policy object of the corresponding type, or dynamically by using the type-erasing execution_policy class.

Implementations may define additional execution policies as an extension. The semantics of parallel algorithms invoked with an execution policy object of implementation-defined type is implementation-defined.

execution policy types
(class)
global execution policy objects
(constant)
dynamic execution policy
(class)
test whether a class represents an execution policy
(class template)

[edit] Exception lists

exceptions raised during parallel executions
(class)

[edit] Parallelized versions of existing algorithms

The TS provides parallelized versions of the following 69 algorithms from <algorithm>, <numeric> and <memory>:

Standard library algorithms for which parallelized versions are provided

[edit] New algorithms

Defined in header <experimental/algorithm>
similar to std::for_each except returns void
(function template)
applies a function object to the first n elements of a sequence
(function template)
Defined in header <experimental/numeric>
(parallelism TS)
similar to std::accumulate, except out of order
(function template) [edit]
similar to std::partial_sum, excludes the ith input element from the ith sum
(function template)
similar to std::partial_sum, includes the ith input element in the ith sum
(function template)
(parallelism TS)
applies a functor, then reduces out of order
(function template) [edit]
applies a functor, then calculates exclusive scan
(function template)
applies a functor, then calculates inclusive scan
(function template)