Limiting the number of threads created
We have a requirement to manually limit the maximum number of worker-threads created by oneTBB. Looking through it code it appears that at the moment the number of workers is determined by the number of cores, multiplied by a factor with a minimum number of 256.
This requirement is largely based on working around a bug in dealing with many task handles in a version of the Linux kernel we cannot upgrade at the moment.
Is there a recommended way to place a hard limit on the number of threads created?
It would be great to understand if:
- this is a feature other people need; or if we need to patch our own copy of TBB?
- it is sufficient to just patch the
AvailableHwConcurrencycode-path andworkers_hard_limitcalculation? - is the guarantee that there are at least 256 workers relied upon anywhere? Will anything break if this is decreased?
Hi @hkleynhans, you can start with global_control with max_allowed_parallelism you can limit amount of threads available for oneTBB (you can lower it or increase).
It will globally affect the target application. I also can suggest to do it together with limiting task_arena concurrency it will help insure proper thread distribution across the task_arenas.
There is an example.
Thanks for the info @pavelkumbrasev - let me test and verify that with our environment
Please reopen this if you are still facing this issue.