Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
9 Views

A template within another template

Hi,

We were looking for a way combining TBB templates with Tasks and didn't find any useful material on the web.

What we want to know is whether we can call a template from another template and expect them to be treated equally (in a sense that all the tasks will be in the same task pool).

Also, the same questionabout creating Tasks in a template. Let's say we create few tasks in a parallel_for(), will they be scheduled together(with the otherfortasks) fairly.

Thanks inAdvance.

0 Kudos
1 Reply
Highlighted
Black Belt
9 Views

"We were looking for a way combining TBB templates with Tasks and didn't find any useful material on the web."
Let's call those (built-in) "algorithms", not "templates".

"What we want to know is whether we can call a template from another template and expect them to be treated equally (in a sense that all the tasks will be in the same task pool)."
Algorithms can be nested freely, which, like recursive parallelism, is often a very good way to create scalabilty, as long as it doesn't imply too much parallel overhead in the inner loops (outer loops are where you get the most benefit). So don't call a parallel algorithm just because it looks sophisticated: make sure it has enough work to do. The scheduler will execute all tasks in the dynamic dependency graph according to its own scheduling algorithm, which heavily discriminates between tasks based on nesting depth, but that's intentional.

"Also, the same questionabout creating Tasks in a template. Let's say we create few tasks in a parallel_for(), will they be scheduled together(with the otherfortasks) fairly."
Algorithms create tasks internally, and the scheduler sees only tasks. For TBB, "fair" is a dirty word (performance is most likely obtained by not being fair), but there is no discrimination between tasks created implicitly (by using the higher-level built-in algorithms) or explicitly in user code.
0 Kudos