Search code examples
tbb

How to resolve “no member named 'task' in namespace 'tbb'” error when using oneDPL?


When I use oneDPL in my code, I face the following issue:

/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/pstl/parallel_backend_tbb.h:70:10: error: no member named 'task' in namespace 'tbb'

Why does this happen and how can I fix it?


Solution

  • It happens when you use oneTBB because oneTBB is not compatible with legacy TBB.

    libstdc++9, libstdc++10 use interfaces of legacy TBB that are not supported by oneTBB. It's fixed for libstdc++11 (See details).

    oneTBB release notes say:

    An application using Parallel STL algorithms in libstdc++ versions 9 and 10 may fail to compile due to incompatible interface changes between earlier versions of Threading Building Blocks (TBB) and oneAPI Threading Building Blocks (oneTBB). Disable support for Parallel STL algorithms by defining PSTL_USE_PARALLEL_POLICIES (in libstdc++ 9) or _GLIBCXX_USE_TBB_PAR_BACKEND (in libstdc++ 10) macro to zero before inclusion of the first standard header file in each translation unit.

    If you use oneDPL, you don't have to apply these workarounds, because oneDPL does it for you, but you need to include its headers before the standard ones. Meanwhile, you can still use Parallel STL algorithms as before since oneDPL implements them.

    If reordering of the headers is not suitable for you, you can define the macros, e.g.:

    dpcpp my_app.cpp -DPSTL_USE_PARALLEL_POLICIES=0 # for libstdc++ 9
    dpcpp my_app.cpp -D_GLIBCXX_USE_TBB_PAR_BACKEND=0 # for libstdc++ 10
    

    If it's also not applicable, try to use legacy TBB instead of oneTBB.