Following web site has small program to parallel sum elements of Vector:
<
http://en.cppreference.com/w/cpp/experimental/reduce
>
<
#include <iostream>
#include <chrono>
#include <vector>
#include <numeric>
// #include <experimental/execution_policy>
// #include <experimental/numeric>
#include <experimental/execution_policy>
#include <experimental/numeric>
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::experimental::parallel::reduce(
std::experimental::parallel::par,
v.begin(), v.end());
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms = t2 - t1;
std::cout << "parallel::reduce result "
<< result << " took " << ms.count() << " ms\n";
}
}
>
Above program output will be:
<
std::accumulate result 5000003.50000 took 12.7365 ms
parallel::reduce result 5000003.50000 took 5.06423 ms
>
I compiled this program using Microsoft Visual C++ 2017 Professional.
Compiler is giving following errors:
cannot open source file "experimental/execution_policy"
cannot open source file "experimental/numeric"
Any information to resolve these compilation errors please?