Community
cancel
Showing results for 
Search instead for 
Did you mean: 
181 Views

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.

 

0 Kudos
2 Replies
181 Views

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 

Mark_L_Intel
Employee
11 Views

Hello,


Apologize for a long response time. The main use programming model in TBB is task based programming. The idea is to abstract out hardware and OS specific concepts such as threads and focus on the tasks instead. You can certainly limit the amount of threads to be used. But beyond that, instead of working with the individual threads the likely more successful strategy will be to focus on tasks instead.


Reply