◐ Shell
clean mode source ↗

并行扩展 - cppreference.com

来自cppreference.com

并入 ISO C++ 此页面上描述的功能自 2016 年 3 月起已并入主线 ISO C++ 标准(除了动态执行策略和 exception_list);见算法库 (C++17 起)

C++ 并行扩展 (C++ Extensions for Parallelism),ISO/IEC TS 19570:2015 为 C++ 标准库定义下列新组件:

执行策略

并行 TS 描述三种执行策略:顺序并行并行加向量,并提供对应的执行策略类型和对象。用户可以通过以对应类型的执行策略对象调用并行算法,静态地选择执行策略,或用类型擦除的 execution_policy 类动态地选择执行策略。

实现可以定义额外的执行策略为扩展。以实现定义类型执行策略对象调用并行算法的语义是实现定义的。

异常列表

既存算法的并行化版本

该 TS 为来自 <algorithm>、<numeric> 和 <memory> 的下列 69 个算法提供并行化版本

提供了并行化版本的标准库算法
  • std::adjacent_difference
  • std::adjacent_find
  • std::all_of
  • std::any_of
  • std::copy
  • std::copy_if
  • std::copy_n
  • std::count
  • std::count_if
  • std::equal
  • std::fill
  • std::fill_n
  • std::find
  • std::find_end
  • std::find_first_of
  • std::find_if
  • std::find_if_not
  • std::generate
  • std::generate_n
  • std::includes
  • std::inner_product
  • std::inplace_merge
  • std::is_heap
  • std::is_heap_until
  • std::is_partitioned
  • std::is_sorted
  • std::is_sorted_until
  • std::lexicographical_compare
  • std::max_element
  • std::merge
  • std::min_element
  • std::minmax_element
  • std::mismatch
  • std::move
  • std::none_of
  • std::nth_element
  • std::partial_sort
  • std::partial_sort_copy
  • std::partition
  • std::partition_copy
  • std::remove
  • std::remove_copy
  • std::remove_copy_if
  • std::remove_if
  • std::replace
  • std::replace_copy
  • std::replace_copy_if
  • std::replace_if
  • std::reverse
  • std::reverse_copy
  • std::rotate
  • std::rotate_copy
  • std::search
  • std::search_n
  • std::set_difference
  • std::set_intersection
  • std::set_symmetric_difference
  • std::set_union
  • std::sort
  • std::stable_partition
  • std::stable_sort
  • std::swap_ranges
  • std::transform
  • std::uninitialized_copy
  • std::uninitialized_copy_n
  • std::uninitialized_fill
  • std::uninitialized_fill_n
  • std::unique
  • std::unique_copy

新算法

在标头 <experimental/algorithm> 定义

类似 std::for_each,但返回 void
(函数模板)
应用函数对象到序列的前 n 个元素
(函数模板)

在标头 <experimental/numeric> 定义

(并行 TS)

类似 std::accumulate,但不按顺序进行
(函数模板) [编辑]
类似 std::partial_sum,从第 i 个和排除第 i 个输入元素
(函数模板)
类似 std::partial_sum,包含第 i 个元素于第 i 个和
(函数模板)
应用函数对象,然后进行不按顺序的规约
(函数模板) [编辑]
应用函数对象,再计算 exclusive_scan
(函数模板)
应用函数对象,再计算 inclusive_scan
(函数模板)