The code below will build and run on my Ubuntu 23.10 system using libstdc++, either with GCC or clang (via g++ execution.cpp -ltbb or clang++ execution.cpp -ltbb):
#include <vector>
#include <execution>
#include <cassert>
int main(int argc, char *argv[])
{
using namespace std;
vector v{1,2,3,4,5,6,7,8};
for_each(std::execution::seq, v.begin(), v.end(), [](auto& x) { x++; });
for_each(std::execution::par, v.begin(), v.end(), [](auto& x) { x++; });
for_each(std::execution::par_unseq, v.begin(), v.end(), [](auto& x) { x++; });
for_each(std::execution::seq, v.begin(), v.end(), [](auto& x) { x++; });
assert((v==vector{5,6,7,8,9,10,11,12}));
return 0;
}
However, if I try to use Clang with libc++ (via clang++ -stdlib=libc++ execution.cpp -ltbb), compilation fails. The execution namespace isn't found, and the first error is:
error: no member named 'execution' in namespace 'std'; did you mean 'exception'?
I have read that a solution is to build LLVM/Clang with PSTL enabled, and so I configured CMake using:
cmake ../llvm \
-DLLVM_USE_LINKER=gold \
-DCMAKE_INSTALL_PREFIX=$PWD/../install_pstl \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" \
-DLLVM_ENABLE_PROJECTS="clang;pstl" \
-DPSTL_PARALLEL_BACKEND=tbb
I then try to compile the earlier program using:
clang++ -std=c++23 -stdlib=libc++ -Wl,-rpath,"$HOME/llvm-project-main/install_pstl/lib:$HOME/llvm-project-main/install_pstl/lib/x86_64-unknown-linux-gnu:$LD_LIBRARY_PATH" execution.cpp
The program again fails to compile. Now the execution namespace is found, but none of the 4 constants (seq,par,unseq and par_unseq). The first error message is:
error: no member named 'seq' in namespace 'std::execution'
Is my configuration wrong? Is there anything I should change in the compiler invocation?
There has been prior discussion of an LLVM bug here, but that has since been closed.