Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2473 Discussions

How do I reference the tbb::task_group_context object inside a parallel_for loop

tbbuser
Novice
844 Views
tbb::task_group_context tg;
SomeClass someObject;

tbb:: parallel_for(tbb::blocked_range<size_t>(0, num, grainSize), 
                   someObject,
                   tbb::simple_partitioner(),
                   tg);
I need to reference tg inside the functor definition of SomeClass so that I can cancel
all the threads under some conditons
lass SomeClass
{
void operator()(const tbb::blocked_range<size_t>& r)  const{
if (somthing < 0) tg.cancel_group_execution(); }

 

I get compiler error : "tg" not declared in this scope. 
How do i reference the "tg" that is being passed into the parallel_for loop
0 Kudos
1 Solution
2 Replies
tbbuser
Novice
723 Views

Thank you for the solution. That works

0 Kudos
Reply