Jak*_*ský 5 c++ parallel-processing c++17
cppreference 对于std::exclusive_scan是这样说的:
d_first - 目标范围的开始;可能等于第一个
std::exclusive_scan所以在“就地”模式下使用覆盖存储应该没有问题。但是,对于 GCC 12.2.0 附带的 libstdc++ 实现,它无法与使用执行策略的重载一起使用,即使它是std::execution::seq. 考虑这个例子:
#include <algorithm>
#include <numeric>
#include <execution>
#include <vector>
#include <cassert>
int main()
{
const int size = 10;
std::vector<int> vec(size);
// without execution policy
std::fill(vec.begin(), vec.end(), 1);
std::exclusive_scan(vec.begin(), vec.end(), vec.begin(), 0);
assert(vec[0] == 0); // the first element should be 0
assert(vec[size-1] == size-1); // the last element should be the sum
// sequential execution policy
std::fill(vec.begin(), vec.end(), 1);
std::exclusive_scan(std::execution::seq, vec.begin(), vec.end(), vec.begin(), 0);
assert(vec[0] == 0); // the first element should be 0
assert(vec[size-1] == size-1); // the last element should be the sum
// parallel execution policy
std::fill(vec.begin(), vec.end(), 1);
std::exclusive_scan(std::execution::par, vec.begin(), vec.end(), vec.begin(), 0);
assert(vec[0] == 0); // the first element should be 0
assert(vec[size-1] == size-1); // the last element should be the sum
}
Run Code Online (Sandbox Code Playgroud)
请参阅 godbolt: https: //godbolt.org/z/Yvax1dz7e
这是 cppreference 文档或 libstdc++ 实现中的错误吗?实际上可以实现并行就地独占扫描算法。
我知道有带有std::exclusive_scan 和执行策略 std::execution::par 的计算前缀积,但它不会询问错误。
[独家.扫描#8]标准的
\n\n\n备注:\xc2\xa0
\nresult\xc2\xa0 可能等于\xc2\xa0first。
此外,与 GCC 和 Clang 不同,最新的 MSVC 接受 C++17 模式下的代码: https: //godbolt.org/z/78W9Wfbvh
\n因此,这是 libstdc++ 实现中的一个错误,而 cppreference 正确地代表了标准的评论。
\n| 归档时间: |
|
| 查看次数: |
193 次 |
| 最近记录: |