有人能告诉我如何为 std::reduce
编译示例代码吗? , 在 cppreference 上?
#include <iostream>
#include <chrono>
#include <vector>
#include <numeric>
#include <execution_policy>
int main()
{
std::vector<double> v(10'000'007, 0.5);
{
auto t1 = std::chrono::high_resolution_clock::now();
double result = std::accumulate(v.begin(), v.end(), 0.0);
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms = t2 - t1;
std::cout << std::fixed << "std::accumulate result " << result
<< " took " << ms.count() << " ms\n";
}
{
auto t1 = std::chrono::high_resolution_clock::now();
double result = std::reduce(std::par, v.begin(), v.end());
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms = t2 - t1;
std::cout << "std::reduce result "
<< result << " took " << ms.count() << " ms\n";
}
}
我在 Mint18 下工作,安装了新的 g++6.2。在编译期间我只使用 -std=c++17
旗帜。想用execution_policy
怎么办? (#include <execution_policy>
)?目前我的编译器告诉我 reduce
不是命名空间 std
的成员并且没有 execution_policy
这样的文件.
最佳答案
libstdc++(默认与 g++ 一起使用)和 libc++(默认与 clang 一起使用)都没有实现 execution_policy 支持。
在 this page 上跟踪了在 libstdc++ 中实现新功能的进展情况.跟踪 libc++ 进度 here .如您所见,截至撰写本文时,P0024R2“并行 TS 应标准化”尚未由任何一个库实现。
关于c++ - 如何使用 g++6 使用 std::reduce 和 #include <execution_policy> 编译代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41081317/