Reputation: 16493
clang++ version:
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Trying some C++ parallelism:
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
#include <random>
#include <math.h>
#define N 10000000
double myFunction(double x) {
return pow(x, x) / (int(x) % 3);
}
int main() {
std::random_device rd;
std::uniform_real_distribution<double> uniform(0.0, 20.0);
std::vector<double> inputs;
std::vector<double> returnValues;
for (int i = 0; i < N; ++i) {
double r = uniform(rd);
inputs.push_back(r);
}
std::transform(std::execution::par_unseq,
inputs.begin(), inputs.end(),
returnValues.begin(),
myFunction);
}
I have tried compiling with all of these:
$ clang++ -std=c++1z go.cpp -o run
$ clang++ -std=c++17 go.cpp -o run
with and without #include <optional>
. But all come up with same compiler errors:
go.cpp:93:25: error: no member named 'execution' in namespace 'std'; did you mean 'exception'?
std::transform(std::execution::par_unseq,
~~~~~^~~~~~~~~
exception
/Library/Developer/CommandLineTools/usr/include/c++/v1/exception:97:29: note: 'exception' declared here
class _LIBCPP_EXCEPTION_ABI exception
^
go.cpp:93:36: error: no member named 'par_unseq' in 'std::exception'
std::transform(std::execution::par_unseq,
~~~~~~~~~~~~~~~~^
2 errors generated.
make: *** [parallel] Error 1
EDIT:
Trying with gcc
doesn't work either:
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ gcc -ltbb -std=c++17 go.cpp -o run
$ gcc -ltbb go.cpp -o run
generate the error:
go.cpp:69:10: fatal error: 'execution' file not found
#include <execution>
^~~~~~~~~~~
1 error generated.
Anyone know how to fix this?
Upvotes: 7
Views: 6961
Reputation: 1009
If you look at the compiler support page on cppreference, you'll notice Apple Clang still doesn't support parallel algorithms.
Upvotes: 9
Reputation: 22152
You are missing
#include<algorithm>
#include<execution>
That being said, according to the compiler support overview at cppreference.com Apple Clang does not yet have support for the parallel algorithms extensions. (Look for "Parallelism TS" on the page.)
Upvotes: 2