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

Switching off the task stealing

azmodai
Beginner
364 Views
Hello,

I would like to know if it is possible to switch the task stealing off when using TBB ?
It appears to be activated by default and I need to switch it off to perform specific tests ....
I looked into the official book and found nothing related to this.

Did somebody already try something like that ?

Thanks a lot !
0 Kudos
2 Replies
anton_pegushin1
Beginner
364 Views
Hi, yes, it is possible. Include task_scheduler_init.h header file and in your code before you run anything related to TBB create a task_scheduler_init object and pass 1 as an argument to the constructor (more info in reference manual).
[cpp]tbb::task_scheduler_init init(1);[/cpp]
This will effectively turn off implicit TBB multi-threading for your application, only one TBB worker thread will be created, the work will be serialized, the tasks will be created in this single thread's task pool and will never be stolen, just taken out and executed. Unfortunately serialization is the only way here, because task stealing is the only mechanism in TBB to share work between threads, so having multiple threads with no stealing means having really just one thread.
Note: if you explicitly create other std::threads and run several algorithms in parallel, I think there still will be stealing between these master threads and task_scheduler_init will not help.
0 Kudos
azmodai
Beginner
364 Views
Ok,
Thanks for your help,
0 Kudos
Reply