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

From Cilk to Intel TBB

erling_andersen
New Contributor I
1,341 Views

Hi

 

I am big fan of Cilk but it is dead. So now I want to use TBB instead. (So I am new to TBB)

I rely on the function

 

__cilkrts_get_worker_number()

 

Therefore, I created a global arena  as follows

 

tbb::task_arena *global_arena=NULL;

int tbb_setnumworkers(integer32 numworkers)
{
  int  ok=1;

  if ( global_arena==NULL )
    global_arena = new tbb::task_arena (numworkers);
}

and then my parallel fors looks like

(*global_arena).execute([=](){ tbb::parallel_for(ufirst,ulast,ustep,[=](uinteger32 i){(*f)(i,arg);}); });

Now I need a thread id I do

 

integer32 tbb_workerid(void)
{
  if ( global_arena==NULL )
    return ( 0 );
  else
    return ( tbb::this_task_arena::current_thread_index() );
} /* tbb_workerid */

It works mostly. However, it seems when tbb_workerid is not called from the thread that created the global_arena then the thread is -1. Well, at least I get -1 in some cases.

Any suggestion for fixing this issue with thread id being -1 in some cases? Or is it impossible?

 

Thanks.

 

Erling

 

0 Kudos
1 Solution
Jeffrey_H_Intel
Employee
1,304 Views

Sorry, my first attempt to answer this was wrong.  I don't think TBB has a way to detect the underlying thread id, by design (https://software.intel.com/en-us/comment/1585082#).

What are you going that requires the thread id?

View solution in original post

0 Kudos
2 Replies
Jeffrey_H_Intel
Employee
1,305 Views

Sorry, my first attempt to answer this was wrong.  I don't think TBB has a way to detect the underlying thread id, by design (https://software.intel.com/en-us/comment/1585082#).

What are you going that requires the thread id?

0 Kudos
James_T_Intel
Moderator
1,274 Views

The current_thread_index function you are using is the best available for getting a thread ID, but as Jeff pointed out thread ID is mostly hidden by design. Please read the discussion he posted regarding it.


I am closing support on this thread. Any further discussion will be considered community only, and Intel support will not be officially handling this thread going forward. If you need Intel support, please post a new thread.


0 Kudos
Reply