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

Several threads executing a root task or a continuation task.

kio_marv
Beginner
644 Views
Hi,
I have a test program with root, child and continuation tasks. Using gdb, I put breakpoints at the execute functions of the root task and the continuation task. When reaching them, I used info threads to see how many threads were running:
[plain]2 Thread 0xb7ed1b70 (LWP 8537)  0x0012d422 in __kernel_vsyscall ()

* 1 Thread 0xb7fd27a0 (LWP 8534)  MyRoot::execute (this=0xb7fb3aa0) at ../src/src/MyRoot.cpp:44
[/plain]
The same output goes for the continuation task.
So my question is if a root task or a continuation task could be executed by more than one thread.

Thanks.

PS: I have a 2 core machine.
0 Kudos
1 Solution
RafSchietekat
Valued Contributor III
644 Views
"So, if in execute() I don't create more child tasks or recycle the task, execute() will be run entirely in one thread, isn't it?"
If you don't create child tasks directly or indirectly, e.g., through parallel_for(), that execute() call will run entirely in one thread. If you recycle the task, execute() may run in a different thread, but not concurrently.

View solution in original post

0 Kudos
6 Replies
RafSchietekat
Valued Contributor III
644 Views
"So my question is if a root task or a continuation task could be executed by more than one thread."
Not concurrently, but the program could have them recycled. What do you have in mind?
0 Kudos
kio_marv
Beginner
644 Views
I thought that execute could be splitted in more than one thread.
0 Kudos
RafSchietekat
Valued Contributor III
644 Views
As used by TBB, execute() may of course create child tasks, and those could well be executed by other threads.
0 Kudos
kio_marv
Beginner
644 Views
Ok!
So, if in execute() I don't create more child tasks or recycle the task, execute() will be run entirely in one thread, isn't it?.

Thanks!
0 Kudos
RafSchietekat
Valued Contributor III
645 Views
"So, if in execute() I don't create more child tasks or recycle the task, execute() will be run entirely in one thread, isn't it?"
If you don't create child tasks directly or indirectly, e.g., through parallel_for(), that execute() call will run entirely in one thread. If you recycle the task, execute() may run in a different thread, but not concurrently.
0 Kudos
kio_marv
Beginner
644 Views
Thanks!!! It's clear now!!!
0 Kudos
Reply