oneTBB icon indicating copy to clipboard operation
oneTBB copied to clipboard

Limiting the number of threads created

Open hkleynhans opened this issue 2 years ago • 2 comments

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 AvailableHwConcurrency code-path and workers_hard_limit calculation?
  • is the guarantee that there are at least 256 workers relied upon anywhere? Will anything break if this is decreased?

hkleynhans avatar Nov 15 '23 15:11 hkleynhans

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.

pavelkumbrasev avatar Nov 15 '23 17:11 pavelkumbrasev

Thanks for the info @pavelkumbrasev - let me test and verify that with our environment

hkleynhans avatar Nov 20 '23 07:11 hkleynhans

Please reopen this if you are still facing this issue.

JhaShweta1 avatar Apr 23 '24 14:04 JhaShweta1