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

Limiting number of threads with task_scheduler_init doesn't work

David_M_13
Beginner
379 Views

Hi,

I'm creating

task_scheduler_init init(9);

and then

task_group group;

It always creates exactly 16 threads, regardless of the number I use in the init.  Do task groups not use task_scheduler_init?

Thanks,

David

0 Kudos
5 Replies
Anton_M_Intel
Employee
379 Views
What do you mean by "creates 16 threads"? 1) Do you see they simultaneously participating in the work? 2) Or do you see that 16 threads can join the work during the whole processing? If (1) is true, please check whether another instance of task_scheduler_init already set the limit for this master thread (only the first specification matters) (2) is expected behavior in case if you have 16 HW threads on your machine.
0 Kudos
David_M_13
Beginner
379 Views
1) It both creates the pool and actually uses them during execution. I also thought perhaps the pool was 16 but not all were used. I don't create another task_scheduler_init instance.
0 Kudos
RafSchietekat
Valued Contributor III
379 Views
Also consider that any TBB scheduler-related call before an explicit task_scheduler_init is put on the application thread's stack will imply the default number of worker threads in that arena, as if there were an implicit task_scheduler_init that the explicit one could not override anymore. Could that be the case?
0 Kudos
David_M_13
Beginner
379 Views
I was instantiating a thread observer before, but I put it after and I'm still getting 16 threads created and used.
0 Kudos
RafSchietekat
Valued Contributor III
379 Views
To be absolutely sure, try putting the task_scheduler_init instance right in main(), so that it is created before anything else and destroyed after anything else. If that works (most likely), try getting gradually back to where you were, to isolate and hopefully remedy the problem. If it doesn't (rather less likely), please provide more information about release version and whatnot, perhaps with a minimal reproducer.
0 Kudos
Reply