Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Brian_Budge
Beginner
173 Views

throttling number of threads

Hi -

Is it possible to throttle the maximum number of threads used by the task scheduler or for a parallel launch? I searched the forums for this, but couldn't find anything. Probably just the wrong key words.

Thanks.
0 Kudos
8 Replies
RafSchietekat
Black Belt
173 Views

Provide a non-default argument to task_scheduler_init.
turks
Beginner
173 Views

Quoting - Raf Schietekat
Provide a non-default argument to task_scheduler_init.
Raf, could you explain further ? What would be a "non default argument" ?

Thanks
-T
173 Views

Quoting - turks
Raf, could you explain further ? What would be a "non default argument" ?

Thanks
-T


From the docs : http://www.threadingbuildingblocks.org/files/documentation/a00114.html

task_scheduler_init (int number_of_threads=automatic, stack_size_type thread_stack_size=0)
Shorthand for default constructor followed by call to intialize(number_of_threads).

-

task_scheduler_init tinit(4); // restrict tbb worker threads to 4, even if you have more or less hardware threads available

Terry_W_Intel
Employee
173 Views

Quoting - turks
Raf, could you explain further ? What would be a "non default argument" ?

Thanks
-T
The task_scheduler_init() can take two optional arguments:

task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0);

So, you can ask directly for p threads by doing this:

task_scheduler_init init(p);

Cheers,
Terry

turks
Beginner
173 Views



From the docs : http://www.threadingbuildingblocks.org/files/documentation/a00114.html

task_scheduler_init (int number_of_threads=automatic, stack_size_type thread_stack_size=0)
Shorthand for default constructor followed by call to intialize(number_of_threads).

-

task_scheduler_init tinit(4); // restrict tbb worker threads to 4, even if you have more or less hardware threads available

Is there any way to know that if you ask for only 2 worker threads on an 8 core machine that you actually got 2 and
not 8 ? If I throttle back the worker threads at init time to 2 it uses as much CPU as when I init with 8.
RafSchietekat
Black Belt
173 Views

Quoting - turks
Is there any way to know that if you ask for only 2 worker threads on an 8 core machine that you actually got 2 and
not 8 ? If I throttle back the worker threads at init time to 2 it uses as much CPU as when I init with 8.
The first task_scheduler_init instance sets the number of worker threads; any additional instances have no say in the matter. If you did provide the number to the first instance, what are the symptoms?
turks
Beginner
173 Views

Quoting - Raf Schietekat
The first task_scheduler_init instance sets the number of worker threads; any additional instances have no say in the matter. If you did provide the number to the first instance, what are the symptoms?
Symptoms of initing to 1 or 2 threads is that my pipeline is using a lot of CPU. I assume the default (if no argument is given) is 8 on a machine with 2 quad-core chips ?
RafSchietekat
Black Belt
173 Views

"Symptoms of initing to 1 or 2 threads is that my pipeline is using a lot of CPU."
That's not very specific.

"I assume the default (if no argument is given) is 8 on a machine with 2 quad-core chips ?"
Yes, unless you also have hyperthreading.
Reply