【问题标题】:Algorithm for [inclusive/exclusive]_scan in parallel <algorithm> proposal N3554[inclusive/exclusive]_scan in parallel <algorithm> 提案 N3554 的算法
【发布时间】: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


【解决方案1】:

Parallel prefix sum 是一种经典的分布式编程算法,它优雅地使用归约和分布(如文章所示)。关键的观察结果是,您可以在知道前导项之前计算出部分和的 部分

【讨论】:

  • 感谢您提供有趣的链接!
  • @AmiTavory:很高兴您喜欢阅读(无论如何我需要刷新自己的记忆)!
猜你喜欢
  • 2014-12-25
  • 2013-11-28
  • 2023-01-16
  • 1970-01-01
  • 2019-05-29
  • 2020-05-03
  • 1970-01-01
  • 2011-09-20
  • 2019-08-24
相关资源
最近更新 更多