My MacOS system is 2 GHz 4 Intel Core i5, and when I set:
tbb::global_control gc(tbb::global_control::max_allowed_parallelism, 10);
I can only get 8 returned by tbb::this_task_arena::max_concurrency()
.
When I increase max_allowed_parallelism
, the max concurrency always returns 8 and cannot increase.
How is max_concurrency()
controlled inside tbb ?
max_allowed_parallelism
allows you to limit the max number of worker threads.
max_concurrency()
returns the concurrency level of the task_arena
currently used by the calling thread. If the thread has not yet initialized the task scheduler, returns the concurrency level determined automatically for the hardware configuration.
This indicates that your current hardware supports having 8 active/running threads at any point in time and there's little point in creating more worker threads than what is supported by hardware. I suggest leaving max_allowed_parallelism
at its default value and you'll get the most out of your hardware.
Example - When I run this program on a computer that I know has 12 hyperthreaded cores (meaning, it can run 2 hardware threads per core), the output will be 24. If I run it on another computer with 6 HT cores, it'll output 12.
#include <tbb/tbb.h>
#include <iostream>
using namespace oneapi;
int main() {
std::cout << tbb::this_task_arena::max_concurrency() << '\n';
}