简体   繁体   中英

Intel oneTBB Ubuntu Linux std::execution::par error

I am having trouble properly using oneTBB on my Ubuntu 20.04. The problem occurs when I want to use std::execution::par with std::for_each for both using CLI g++ and cmake. I have gcc 9.4.0.

This is the procedure I follow:

  • I have installed oneTBB using the Intel GUI from Intel's web page ( here ).

  • I have set the environment using "source vars.sh" in /tbb/latest/env (explained here ).

  • I have a sample code:

test.cpp:

#include <iostream>
#include <vector>
#include <algorithm>
#include <execution>

int main(){
    std::vector<int> vec = {1, 2, 3, 4, 5, 10, 20, 4 };

    std::sort(std::execution::seq, vec.begin(), vec.end()); // sequential
    std::sort(std::execution::par, vec.begin(), vec.end()); // parallel

    return 0;
}
  • I tried the following command:

     g++ -std=c++17 -o test test.cpp -ltbb

    this does not work and give many errors.

  • I tried the command line as explained here :

     g++ -o test test.cpp $(pkg-config --libs --cflags tbb)

    it gives the following error:

     error: 'std::execution' has not been declared

    pointing to the line std::sort lines.

  • I tried the following (based on here) cmake file with no luck:

     cmake_minimum_required(VERSION 3.22) project(test) set(CMAKE_CXX_STANDARD 20) list(APPEND CMAKE_MODULE_PATH "/home/username/oneapi/tbb/latest/lib/cmake/tbb") #set(CMAKE_MODULE_PATH "/home/username/oneapi/tbb/latest/lib/cmake/tbb") #this did not work either add_executable(test test.cpp) find_package(TBB REQUIRED) target_link_libraries(${PROJECT_NAME} tbb)
  • Interestingly, the examples given here are all working. I can build and run them all (except the MKL examples). None of these examples have #include <execution> and std::execution::par in them tough, as far as I can see.

  • In one of the oneTBB examples (eg fibonacci), if I only include <execution> to the example source code, it does not give error with the 5th and 6th option above. But when I want to use std::execution::par in the code, it does not compile. So examples are not working when std::execution::par comes into play.

  • Older version of TBB that can be installed using apt , does not give this error.

Any help is appreciated.

Detailed explanation in this thread

You are using oneDPL APIs in your example, so it is not about TBB per se. In fact, TBB is just one of the backends that can be used with oneDPL -- another one is OpenMP. With TBB backend, you can get into the errors that are indeed coming from the issues connected to TBB backend incorrect usage -- one aspect of that described in one of the responses above. With oneAPI, we switched to new oneTBB from older (and incompatible with new one) "old" TBB -- that also can spill out into the compilation process. The advice is to put oneDPL headers first into your source code (eg, before standard library headers) -- that should be sufficient to automatically call correct TBB backend.

We already have documentation regarding oneDPL, eg, please see

https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-library-guide/top.html

where the solution (found by you) to the errors you first seen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM