Thread ID as index from zero to thread number

Thread ID as index from zero to thread number


Dear TBB experts,

 

I am now thinking of parallel efficient algorithm by using TBB.

Thus, I would like to prepare some pool data (std::vector container) per each thread in RAII phase,

and make each thread to access by their own id (thread id, I meant).

Currently, I initialized scheduler as tbb::task_scheduler.initialize(thread_num),

and prepared std::vector<PoolDataStructure> _pool(thread_num),

then, for accessing it, I use the return value of tbb::task_arena::current_thread_index() as their thread id.

 

Seemingly, it works well, but I wonder this is whether correct or not as specification.

(When I run the program based on the above, I encountered different numerical result with serial or parallel.

 I am afraid that there is some data race due to the above implementation, or others)

 

I would appreciate it if you could consider it.

 

2 posts / 0 new

P.S.

I know that there is a procedure unit, "thread" and "task", and tbb adopt task as the minimum unit for its parallelization.

I wonder how tbb could differentiate thread and task as index (in my context, between thread id & task id).

that tbb::task_arena::current_thread_index() might return the thread id as named,

but I am afraid that when the same thread deals with different tasks, the pool data I prepared will be violated by them in data-race manner.

 

If you know how to think about handling&differentiating thread & task,

I sincerely hope to understand it.

 

Kind regards 

Leave a Comment

Please sign in to add a comment. Not a member? Join today