I am trying to implement a simple use-case reduce() and std:: execution. I am using C++ 17 standard for the following code. However, the following code still does not get compiled.
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <execution>
int main() {
std:: vector<int> vec(10);
std:: iota(std::begin(vec), std::end(vec), 1);
const auto result = std::reduce(std::execution::par, std::begin(vec),
std::end(vec));
std:: cout << result;
return 0;
}
C:\Users\Blind1729\Desktop>g++ --std=c++17 a.cpp
a.cpp: In function 'int main()':
a.cpp:8:25: error: 'reduce' is not a member of 'std'
const auto result = std::reduce(std::execution::par, std::begin(vec),
^
a.cpp:8:42: error: 'std::execution' has not been declared
const auto result = std::reduce(std::execution::par, std::begin(vec),
You need to link against TBB, as it is a dependence of the parallel STD (see C++17 STL Parallel Algorithms - with GCC 9.1 and Intel TBB on Linux and macOS):
g++ --std=c++17 a.cpp -ltbb
And make sure you have at least GCC 9.1 installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With