c++macosparallel-processingcputbb

Why tbb::this_task_arena::max_concurrency() cannot increase without limitation?


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 ?


Solution

  • 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';
    }