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

Querring for number of threads in TBB

akhal
Beginner
797 Views
Hej

In my application, I am specifying grainsize for parallel_for:blocked_range, which depends upon number of available/working threads. I specify number of threads by

task_scheduler_init initTBB(nthreads);

But during program execution, I want to confirm there are "nthreads" running, so is there any function/API that returns number of threads TBB has created?
0 Kudos
1 Reply
Kirill_R_Intel
Employee
797 Views
Hi Akhal,

TBB always creates nthreads passed to task_scheduler_init. So there is no need to ensure how many worker threads are created if you specified it explicitly.
In run time TBB scheduler manages tasks executed by the worker threads. If there is no enough job for some threads they will wait inactively. So the number of created threads is constant, but number of active worker threads at the moment is variable. Intention is to leave TBB runtime tobalance loadbetweenthe worker threads and manage number of worker threads at the moment.

Regards,
Kirill
0 Kudos
Reply