How to use experimental parallel STL in C++1z?

断了今生、忘了曾经 提交于 2019-12-22 08:35:45

问题


I want to try parallel STL of C++17. However, I can't find experimental/execution_policy in libc++. How can I try this?

I'm trying http://en.cppreference.com/w/cpp/experimental/reduce, which says I should include these files, but I cannot find execution_policy.

#include <experimental/execution_policy>

After I install libc++ (I followed http://libcxx.llvm.org/docs/BuildingLibcxx.html), I tried the following commands, but in vain.

$ clang++-3.5 -std=c++1z test.cpp -lc++experimental
test.cpp:5:10: fatal error: 'experimental/execution_policy' file not found
#include <experimental/execution_policy>
         ^
1 error generated.

Is this not implemented yet?


回答1:


Is this not implemented yet?

That is correct. Neither the parallelism TS (which would live in <experimental/xxx> or the parallel algorithms in the (not yet final) C++1z standard have been implemented in libc++ (yet).




回答2:


I use the implementation of PSTL in Intel 18 Parallel Studio XE beta, which composes with both libc++ and libstdc++ and is based on TBB. I've tested for_each and transform but nothing else.

Update: The Intel PSTL is open-source (https://github.com/intel/parallelstl) and works with GCC and Clang.

Because support for PSTL is limited, I make the code portable via the preprocessor:

#if defined(USE_PSTL) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1800)
  std::for_each( pstl::execution::par, std::begin(range), std::end(range), [&] (int i) {
    std::for_each( pstl::execution::par_unseq, std::begin(range), std::end(range), [&] (int j) {
#elif defined(USE_PSTL) && defined(__GNUC__) && defined(__GNUC_MINOR__) \
                        && ( (__GNUC__ == 8) || (__GNUC__ == 7) && (__GNUC_MINOR__ >= 2) )
  __gnu_parallel::for_each( std::begin(range), std::end(range), [&] (int i) {
    __gnu_parallel::for_each( std::begin(range), std::end(range), [&] (int j) {
#else
#warning Parallel STL is NOT being used!
  std::for_each( std::begin(range), std::end(range), [&] (int i) {
    std::for_each( std::begin(range), std::end(range), [&] (int j) {
#endif
        B[i*order+j] += A[j*order+i];
        A[j*order+i] += 1.0;
      });
    });
  }

You can see that this code is based on libc++ on Mac, although the PSTL part itself is from the Intel headers, which in turn use TBB as the runtime.

$ otool -L transpose-vector-pstl
transpose-vector-pstl:
    @rpath/libtbb.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
    @rpath/libiomp5.dylib (compatibility version 5.0.0, current version 5.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2)

Full disclosure: I work for Intel and have discussed this implementation with the developers, although I am in no way responsible for it.



来源:https://stackoverflow.com/questions/44020846/how-to-use-experimental-parallel-stl-in-c1z

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!