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

Implicit vs Explicit Task Creation

nagy
New Contributor I
507 Views
What are the performance differences between implicit task creation e.g
[cpp]tbb::parallel_invoke
[&]
{
    tbb::parallel_invoke
    [&]
    {
         tbb::parallel_for( /* .... */ );
    },
    [&]
    {
       // Work
    });
},
[&]
{
    // Work
});[/cpp]
vs explicitly allocating tasks, spawning them, and maybe recycling them.
0 Kudos
8 Replies
Dmitry_Vyukov
Valued Contributor I
507 Views
In general, implicit task creation (especially algorithms like parallel_for) should be considered as more efficient, because that way your program communicates much more information to a tasking library. A library receives information about algorithm structure, total task count, task sizes (algorithms like parallel_for assume roughly equal size tasks), etc. While with explicit task creation a tasking library operates mostly "blindly".

0 Kudos
RafSchietekat
Valued Contributor III
507 Views

Really? I would say that the algorithms have been designed to use tasks well, by the same team and with incremental improvements based on experience, so they would be difficult to match or improve upon economically, but I'm not sure that there's much going on in the other direction. Do you have any examples?

0 Kudos
Dmitry_Vyukov
Valued Contributor I
507 Views
What do you mean by "other direction"? And examples of what do you want?
0 Kudos
RafSchietekat
Valued Contributor III
508 Views
Algorithms try to use tasks efficiently (they're built on top of facilities provided by the scheduler), but do you have examples of what tasks know about algorithms (the "other direction")?
0 Kudos
Dmitry_Vyukov
Valued Contributor I
508 Views
No, I don't have. And I doubt they exist.

0 Kudos
RafSchietekat
Valued Contributor III
508 Views

Then I guess I don't understand what you mean by "While with explicit task creation a tasking library operates mostly "blindly"".

0 Kudos
Dmitry_Vyukov
Valued Contributor I
508 Views
I meant that tasking library executes explicit tasks without any high-level optimizations, because it does not have any information on algorithm structure, total number of tasks, task sizes, etc.
0 Kudos
RafSchietekat
Valued Contributor III
508 Views

What "high-level optimisations" that you couldn't apply yourself if you really wanted to reinvent the wheel or if you had a need not currently provided for by the provided algorithms? Do they use significant private API, perhaps? I would have to look through the sources to find out for myself, but, whileit seems interesting,it would be far easier for you to prove a positive than for me to prove a negative. :-)

0 Kudos
Reply