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

TBB Newbie Question about tasks and parallel_for

reportbase
Beginner
267 Views
Lets say that I have six tasks, broken up into two groups.

1) A B C
2) D E F

I want to complete tasks A, B and C first.

Somthing like this:

paralell_for(A,C, do_something());

After the first three have completed, I want to run the next
three.

parallel_for(D, F, do_something_else());

Any ideas about how to proceed.

Just running the two parallel_for statements in serial obviously does not work here.

I need to somehow wait until the first three tasks are completed to begin the final three tasks?

Thanks.

0 Kudos
2 Replies
Nav
New Contributor I
267 Views

Even I'm new to TBB, but from what I know, in your case, it would probably not be best to use parallel_for.

Your tasks A, B and C, if they are bunches of lines of code that can be executed independent of each other, or if they're functions, they can be executed with the concept of \\"tasks\\" which is different from parallel_for.

Have a look at section 11 of the TBB tutorial. You can execute functions (sections of code, literally) concurrently by creating tasks with the 'new' keyword.

My knowledge in this area is limited...you'll receive much more experienced replies soon :) If my reply is wrong, I'm open to corrections. It'll help me learn too.

In the meantime, it'd help if you'd explain your problem in a little more detail. With a code sample if possible.
0 Kudos
Alexey-Kukanov
Employee
267 Views

Your tasks A, B and C, if they are bunches of lines of code that can be executed independent of each other, or if they're functions, they can be executed with the concept of \\\\\\\\\\\\\\"tasks\\\\\\\\\\\\\\" which is different from parallel_for.

That's basically right, except that direct use of tasks is not recommended, and instead we suggest parallel_invoke or task_group in TBB 2.2. E.g.

[bash]parallel_invoke(A,B,C);
parallel_invoke(D,E,F);
[/bash]

should just do what you want. For the usage of task_group (which is little bit more complex but also more powerful), see the reference manual.

0 Kudos
Reply