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

Can I start a loop using the task scheduler?

smasherprog
Beginner
257 Views

I would like to start the root in main(). Then have the root class spawn a continuation called Stage1, then have stage1 allocate a continuation called Stage2, then have Stage 2 allocate a continuation of the root class?

Would this work? calling continuations in a loop? I would check in the root class whether I should continue or exit the loop.

0 Kudos
3 Replies
robert-reed
Valued Contributor II
257 Views
Quoting - smasherprog
I would like to start the root in main(). Then have the root class spawn a continuation called Stage1, then have stage1 allocate a continuation called Stage2, then have Stage 2 allocate a continuation of the root class?

Would this work? calling continuations in a loop? I would check in the root class whether I should continue or exit the loop.

What do you mean by "allocate a continuation of the root class?" A continuation task is scheduled to execute after the associated child tasks, either by previous planning (allocate continuation) or in the midst of task execution (recycle as continuation). In either case, the continuation task executes after all the children have completed and instead of the previous parent task. Root tasks have no parent and so can't replace a parent to execute after some children. However, you could have the Stage 2 task allocate yet another continuation task to execute after Stage 2's children, a "Stage 3" and continue that pattern of creating children and a new continuation task to execute when they finish. Is that the sort of idea you had in mind?

0 Kudos
smasherprog
Beginner
257 Views

yeah.... I asked just because I wasnt sure if there could be any wierd problems that I couldnt forsee with the TBB library. tnx

0 Kudos
robert-reed
Valued Contributor II
257 Views
Quoting - smasherprog
yeah.... I asked just because I wasnt sure if there could be any wierd problems that I couldnt forsee with the TBB library.

That's the thing about weird problems: they're usually unforeseen ;-). And as much as the technique is theoretically possible, I haven't actually written any code that uses such a pattern, so there may be something unforeseen, a possibility that always exists when trying something new. I'd suggest starting off with a simple test to convince yourself of the viability of the technique and to gain confidence using the library before investing a lot of time in the method.
0 Kudos
Reply