From Cilk to Intel TBB

From Cilk to Intel TBB



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




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 );
    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?






1 post / 0 new