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

A template within another template

ajol
Beginner
211 Views
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
RafSchietekat
Valued Contributor III
211 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
Reply