for cross-reference: i asked also at llvm-bug-tracker: https://github.com/llvm/llvm-project/issues/57898
Steps to reproduce:
Ubuntu with clang from apt.llvm.org and with potential pstl backends installed via libtbb2-dev and clang-15-openmp is not able to compile with C++17 feature std::execution::par.
Dockerfile:
FROM ubuntu:22.04
RUN apt-get update && apt-get -y install
software-properties-common gpg wget
make libssl-dev
RUN apt-get install -y build-essential libthrust-dev libtbb2-dev libtbb2
# https://apt.llvm.org/
RUN wget https://apt.llvm.org/llvm.sh &&
chmod +x llvm.sh &&
./llvm.sh 15 all
ENV PATH=$PATH:/usr/lib/llvm-15/bin
RUN echo "
n#include <execution> n
n#include <algorithm> n
n#include <vector> n
int main(void) { n
std::vector<float> images = {1,2,3,4,5}; n
std::vector<float> results; n
results.resize(images.size()); n
std::transform(std::execution::par, images.begin(), images.end(), results.begin(), [](const auto &input){ return input; }); n
}" > hello.cpp
RUN clang -std=c++17 -stdlib=libc++ hello.cpp -o hello && ./hello
produces following error:
hello.cpp:11:26: error: no member named 'execution' in namespace 'std'; did you mean 'exception'?
std::transform(std::execution::par, images.begin(), images.end(), results.begin(), [](const auto &input){ return input; });
~~~~~^~~~~~~~~
exception
/usr/lib/llvm-15/bin/../include/c++/v1/exception:100:29: note: 'exception' declared here
class _LIBCPP_EXCEPTION_ABI exception
^
hello.cpp:11:37: error: no member named 'par' in 'std::exception'
std::transform(std::execution::par, images.begin(), images.end(), results.begin(), [](const auto &input){ return input; });
~~~~~~~~~~~~~~~~^
2 errors generated.
The command '/bin/sh -c clang -std=c++17 -stdlib=libc++ hello.cpp -o hello && ./hello' returned a non-zero code: 1
Nevertheless, godbold shows that clang-15 should be possible to compile so:
https://godbolt.org/z/3TxoWEMxb
Am i am missing something ubuntu specific here, or do i really have to compile the llvm-stack myself because of potentially missing pstl flag of apt.llvm.org shipped packages?
2
Answers
It’s right, most
libcxx
implementation shiped by system doesn’t provide withpstl
and compile withLIBCXX_ENABLE_PARALLEL_ALGORITHMS
. Unless, you compile llvm and libcxx with specific options, you can’t get these headers. The deep reason behind this is becausepstl
is not completed thus not integrated withlibcxx
.The problem is not related to compilers, but to implementations of the C++ standard library.
According to the compiler suppor table as well as libc++ documentation, libc++ is still missing the support for C++17 parallel algorithms and execution policies.
On Godbolt, Clang uses libstdc++ by default. That’s why it compiles, even with Clang. With using libc++ instead, the compilation will fail. Live demo: https://godbolt.org/z/dMPP7sssa.