【发布时间】:2015-09-08 13:06:40
【问题描述】:
针对 C++14 的提案 N3554 (A Parallel Algorithms Library),提出了(除其他事项外)当前 std::partial_sum 的并行版本,例如:
template<
class ExecutionPolicy,
class InputIterator,
class OutputIterator,
class BinaryOperation>
OutputIterator inclusive_scan(
ExecutionPolicy &&exec,
InputIterator first,
InputIterator last,
OutputIterator result,
BinaryOperation binary_op);
有解释
效果:对于[result,result + (last - first))中的每个迭代器i,执行*i = prefix_sum, 其中 prefix_sum 是相应 sum init + *iter_0 + *iter_1 + *iter_2 + 的结果 ... 或 binary_op(init, binary_op(*iter_0, binary_op(*iter_1, binary_op(*iter_2, ...))) 对于 [first,first + (i - result) - 1) ... 范围内的每个迭代器 iter_j ... 和的操作数的顺序是未指定的。
这个操作如何并行进行?似乎,几乎按照定义,必须计算每个输出 prefix_sum 才能计算下一个要计算的 - 本质上会导致串行操作。
编辑非常感谢 Aasmund Eldhuset 的回答。就个人而言,我发现"Prefix Sums and Their Applications" by Guy E. Blelloch 非常有用。
【问题讨论】:
-
看起来不错且易于阅读的论文;谢谢!
标签: c++ algorithm parallel-processing c++14