Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2470 Discussions

global_control API semantics TO limit number of TBB workers

yaridor
Beginner
233 Views

Hello,

 

I would liked to limit TBB workers in my app to 4. This means that all "parallel_for" constructs will use exactly 4 workers. 

 

I have few questions:

 

1.

should the "max_allowed_parallelism"  parameter of global_control be specified to 4 or 5 (I got confused since the documentation in https://spec.oneapi.io/versions/1.1-rev-1/elements/oneTBB/source/task_scheduler/scheduling_controls/global_control_cls.htm says that the actual value of this parameter is actually  "parameter-value - 1")

 

2.

Are there other ways to limit the number for TBB workers in a specific app?

 

3.

can I assume that by default the main thread of the app is always blocked until "parallel_for" is completed and it does NOT become one the the workers during "parallel_for" ?  

 

Thanks, Yariv

 

0 Kudos
1 Solution
Mark_L_Intel
Moderator
77 Views

Hello @yaridor,

 

    The main thread does participate in the work during a parallel_for call, effectively acting as one of the worker threads. So, if you want to limit the total number of threads (including the main thread) to 4, you should set max_allowed_parallelism to 4. This way, you’ll have 3 worker threads plus the main thread, totaling 4 threads executing the parallel_for tasks.

I'm not sure I understand your question 2. The global_control allows you to control the number of threads (see above, the first paragraph).  You could also create task arenas and limit the number of workers for each arena.     

       

View solution in original post

0 Kudos
1 Reply
Mark_L_Intel
Moderator
78 Views

Hello @yaridor,

 

    The main thread does participate in the work during a parallel_for call, effectively acting as one of the worker threads. So, if you want to limit the total number of threads (including the main thread) to 4, you should set max_allowed_parallelism to 4. This way, you’ll have 3 worker threads plus the main thread, totaling 4 threads executing the parallel_for tasks.

I'm not sure I understand your question 2. The global_control allows you to control the number of threads (see above, the first paragraph).  You could also create task arenas and limit the number of workers for each arena.     

       

0 Kudos
Reply