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

task reference count

mani17
Beginner
345 Views
Hi,

I am new to tbb and am trying to understand the workings of tbb scheduler. I am still not convinced that I correctly understand the purpose of task reference count.

I understand the following points

- I need to set it before spawning any child tasks.
- I need to set it to (number of child +1) if I need the parent to block i.e. for wait_for_all to work.
- If i am using continuation , I have to set ref count for the continuing task.

However I still don't understand, why was this exposed to the user? In other words I can not think of a situation where I would want to set it to any number other than

(number of child) or (number of child +1) or ( just increment count by 1)

Why can't this automatically be done, assuming we have a construct that enables us to specify our intent to wait for children before launching them.

I see that this is done in the allocate_additional _child_of method.

Thanks!

Regards,
Manisha

0 Kudos
1 Solution
Alexey-Kukanov
Employee
345 Views
> Why can't this automatically be done

Short answer: for efficiency reasons.

The task interface was never considered a primary user API in TBB; it evolved as the underlying mechanism to implement parallel algorithms. So it favors efficiency over simplicity. A separate method to set the reference counter, plus certain discipline to calculate and set it appropriately before spawning any childtask, allows to use one plain store instead of several atomic adds. It is still important for performance, and was even more important 6 years ago when TBB started.

If you need a convenient mechanism to work with individual tasks, look at the task_group class.

View solution in original post

0 Kudos
2 Replies
Alexey-Kukanov
Employee
346 Views
> Why can't this automatically be done

Short answer: for efficiency reasons.

The task interface was never considered a primary user API in TBB; it evolved as the underlying mechanism to implement parallel algorithms. So it favors efficiency over simplicity. A separate method to set the reference counter, plus certain discipline to calculate and set it appropriately before spawning any childtask, allows to use one plain store instead of several atomic adds. It is still important for performance, and was even more important 6 years ago when TBB started.

If you need a convenient mechanism to work with individual tasks, look at the task_group class.
0 Kudos
mani17
Beginner
345 Views
Thanks a lot for your reply.

Regards,
Manisha
0 Kudos
Reply