Reputation: 1295
I wanted to use the parallel version of std::sort
where I can specify an execution policy like std::execution::par_unseq
.
I'm currently using clang++-10
and g++ 7.5.0
under Ubuntu Linux, but both don't find the required include file execution
, so apparently the parallel algorithm is not yet supported in these compiler versions.
Can someone please tell me which version of clang
and gcc
would support this feature?
Upvotes: 6
Views: 4730
Reputation: 17379
poolSTL is a single-header implementation of some parallel C++17 algorithms, including sort:
#include <poolstl/poolstl.hpp>
std::sort(poolstl::par, vec.begin(), vec.end());
It works on GCC 7 and versions of Clang missing native support.
There's also pluggable_sort
to parallelize other fast sequential sorts, like pdqsort:
poolstl::pluggable_sort(poolstl::par, vec.begin(), vec.end(), pdqsort);
Upvotes: 4
Reputation: 21307
C++17 execution policies are supported by GCC 10 and Clang 11.
Here is a demo example https://gcc.godbolt.org/z/xahs5x1Kx
#include <execution>
int main()
{
int a[] = {2,1};
std::sort(std::execution::par_unseq, std::begin(a), std::end(a) );
return a[0];
}
Upvotes: 4