如何使用 g++6 编译带有 std::reduce 和 #include <execution_policy> 的代码?
How to compile code with std::reduce and #include <execution_policy> using g++6?
有人可以告诉我如何为 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";
}
}
我在安装了新的 g++6.2 的 Mint18 下工作。在编译期间我只使用 -std=c++17
标志。想用execution_policy
(#include <execution_policy>
)怎么办?目前我的编译器告诉我 reduce
不是命名空间 std
的成员并且没有 execution_policy
.
这样的文件
有人可以告诉我如何为 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";
}
}
我在安装了新的 g++6.2 的 Mint18 下工作。在编译期间我只使用 -std=c++17
标志。想用execution_policy
(#include <execution_policy>
)怎么办?目前我的编译器告诉我 reduce
不是命名空间 std
的成员并且没有 execution_policy
.