5

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?

Fedor
  • 17,146
  • 13
  • 40
  • 131
Ralf
  • 1,203
  • 1
  • 11
  • 20
  • 3
    libstdc++ 9, not in libc++ yet: https://en.cppreference.com/w/cpp/compiler_support – Alan Birtles Jun 05 '21 at 11:12
  • @AlanBirtles: Thanks a lot. Is the version of `libstdc++` bound to a version of `g++` or a version of `Ubuntu`? The relationship is not clear to me. It seems the include files of STL are in my case in '/usr/include/c++/7/' (and also in '/usr/include/boost/'), so apparently I have version 7 (is that used by both 'g++' and 'clang++'?). – Ralf Jun 05 '21 at 11:50
  • 1
    it'd normally be the same version as g++ but I'm not sure it has to be – Alan Birtles Jun 05 '21 at 11:51

1 Answers1

4

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];
}
Fedor
  • 17,146
  • 13
  • 40
  • 131
  • 2
    Thanks a lot. I can confirm that it is supported by `g++-11.1`. In our case it was also necessary to install a new version of the Intel Thread Building Blocks library (TBB-2019), see also https://stackoverflow.com/a/55989883/3852630. – Ralf Aug 01 '21 at 07:49
  • 1
    Even the current Clang 15 does not support C++17 execution policies. You can try that on the linked Godbolt Compiler website. – mcserep Dec 15 '22 at 21:20
  • 1
    @mcserep, thanks, indeed the standard library `-stdlib=libc++` of Clang misses that support. But if Clang uses GNU standard library `-stdlib=libstdc++` then execution policies are supported as the demo shows. – Fedor Dec 16 '22 at 09:50
  • is it supported for android NDK ? – madan kandula Dec 31 '22 at 14:54