Community
cancel
Showing results for 
Search instead for 
Did you mean: 
wrjj37
Beginner
287 Views

'tbb::task' has not been declared

I compile the code example in Pro TBB on page 13:
 
#include <iostream>
#include <vector>
#include <pstl/execution>
#include <pstl/algorithm>

int main() {
	std::vector<std::string> v = {" Hello ", " Parallel STL!"};
	std::for_each(pstl::execution::par, v.begin(), v.end(),
		[](std::st))
}
But I met some compile errors, and after fixing these errors:
#include <iostream>
#include <vector>
#include <oneapi/dpl/algorithm>
#include <oneapi/dpl/execution>

int main() {
  std::vector<std::string> v = { " Hello ", " Parallel STL! " };
  std::for_each(dpl::execution::par, v.begin(), v.end(),
    [](std::string& s) { std::cout << s << std::endl; }
  );
  return 0;
}
It still not work. The compile command is:
g++ -std=c++2a fig_1_05.cpp -ltbb
The first n lines of error messages are:
In file included from /usr/local/include/c++/10.2.0/pstl/parallel_backend.h:16,
                 from /usr/local/include/c++/10.2.0/pstl/algorithm_impl.h:22,
                 from /usr/local/include/c++/10.2.0/pstl/glue_execution_defs.h:50,
                 from /usr/local/include/c++/10.2.0/execution:32,
                 from /opt/intel/oneapi/dpl/2021.1.2/linux/include/oneapi/dpl/execution:32,
                 from fig_1_05.cpp:28:
/usr/local/include/c++/10.2.0/pstl/parallel_backend_tbb.h: In function 'void __pstl::__par_backend::__cancel_execution()':
/usr/local/include/c++/10.2.0/pstl/parallel_backend_tbb.h:70:10: error: 'tbb::task' has not been declared
   70 |     tbb::task::self().group()->cancel_group_execution();
      |
And the code at line 70 in parallel_backend_tbb.h is:
// Wrapper for tbb::task
inline void
__cancel_execution()
{
    tbb::task::self().group()->cancel_group_execution();
}
Then I found that the same position in GCC current master branch is:
// Wrapper for tbb::task
inline void
__cancel_execution()
{
#if TBB_INTERFACE_VERSION <= 12000
    tbb::task::self().group()->cancel_group_execution();
#else
    tbb::task::current_context()->cancel_group_execution();
#endif
}
The version of GCC and TBB are 10.2.0 and 2021.1.1, respectively.

How should I fix this error?
 
If I use -std=c++11 to compile this code, I need to include an extra header file oneapi/dpl/pstl/parallel_backend_tbb.h in oneapi/dpl/latest/linux/include/oneapi/dpl/internal/function.h, or I will get compile error like below:
 
$ g++ -std=c++11 fig_1_05.cpp -ltbb

In file included from /opt/intel/oneapi/dpl/2021.1.2/linux/include/oneapi/dpl/internal/exclusive_scan_by_segment_impl.h:22,
                 from /opt/intel/oneapi/dpl/2021.1.2/linux/include/oneapi/dpl/execution:44,
                 from fig_1_05.cpp:28:
/opt/intel/oneapi/dpl/2021.1.2/linux/include/oneapi/dpl/internal/function.h:62:20: error: 'oneapi::dpl::__par_backend' has not been declared
   62 | using oneapi::dpl::__par_backend::__buffer;
      |                    ^~~~~~~~~~~~~
0 Kudos
6 Replies
GouthamK_Intel
Moderator
266 Views

Hi,

Thanks for reaching out to us!

We are escalating this thread to the Subject Matter Expert (SME) who will guide you further.

Have a Good day!


Thanks & Regards

Goutham


Mark_L_Intel
Employee
258 Views

the Pro TBB book was published before new TBB revamp effort finalized -- incidentally at the same time as oneTBB project was underway. Many examples from the book do not compile anymore. You can see revamp document describing old TBB API and new TBB API at https://software.intel.com/content/www/us/en/develop/articles/tbb-revamp.html -- look for pdf doc link there. In particular tbb:: task API got deprecated which maybe a reason for the errors you see. However, PSTL code you use still should compile in my view -- so it is worth further investigation on our side -- I emailed your question internally.


Mark_L_Intel
Employee
229 Views

corrected version below.

Mark_L_Intel
Employee
226 Views

This is a known oneTBB issue because 2021.1.1 is not compatible with older TBB interfaces that GCC 10.2 relies on -- “New in 2021.1-beta10 Release” at https://software.intel.com/content/www/us/en/develop/articles/intel-oneapi-threading-building-blocks...:

 

Known Limitations

·        An application using Parallel STL algorithms in GCC 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 GCC 9) or _GLIBCXX_USE_TBB_PAR_BACKEND (in GCC 10) macro to zero before inclusion of the first standard header file in each translation unit.


One option is to revert to an older TBB before trying to use PSTL in GCC.


you can also try the following workaround -- try to reorder the included headers:

include the oneDPL headers first,

and other STL headers second.


it was know to help in similar situation.




wrjj37
Beginner
157 Views

After defining  _GLIBCXX_USE_TBB_PAR_BACKEND to zero and reordering the included headers:

#define _GLIBCXX_USE_TBB_PAR_BACKEND 0

#include <oneapi/dpl/algorithm>
#include <oneapi/dpl/execution>
#include <iostream>
#include <vector>

int main() { 
  std::vector<std::string> v = { " Hello ", " Parallel STL! " };
  std::for_each(dpl::execution::par, v.begin(), v.end(),
    [](std::string& s) { std::cout << s << std::endl; }
  ); 
  return 0;
}

I got another error I have mentioned before:

$ g++ -std=c++2a fig_1_05.cpp -ltbb

In file included from /opt/intel/oneapi/dpl/2021.1.2/linux/include/oneapi/dpl/internal/exclusive_scan_by_segment_impl.h:22,
                 from /opt/intel/oneapi/dpl/2021.1.2/linux/include/oneapi/dpl/execution:44,
                 from fig_1_05.cpp:29:
/opt/intel/oneapi/dpl/2021.1.2/linux/include/oneapi/dpl/internal/function.h:62:20: error: 'oneapi::dpl::__par_backend' has not been declared
   62 | using oneapi::dpl::__par_backend::__buffer;
      |
......

 

wrjj37
Beginner
139 Views

I found the solution to fix "'oneapi::dpl::__par_backend' has not been declared" error:

#include <oneapi/dpl/execution>
#include <oneapi/dpl/algorithm>
#include <iostream>
#include <vector>

int main() { 
  std::vector<std::string> v = { " Hello ", " Parallel STL! " };
  std::for_each(dpl::execution::par, v.begin(), v.end(),
    [](std::string& s) { std::cout << s << std::endl; }
  ); 
  return 0;
}

After exchanging <oneapi/dpl/execution> and <oneapi/dpl/algorithm>, everything is ok.