Community
cancel
Showing results for 
Search instead for 
Did you mean: 
mani17
Beginner
87 Views

task reference count

Jump to solution
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_K_Intel3
Employee
87 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

2 Replies
Alexey_K_Intel3
Employee
88 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

mani17
Beginner
87 Views
Thanks a lot for your reply.

Regards,
Manisha
Reply