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

max n of threads used by an algorithm

Zoltan_T_
Beginner
260 Views

For example I may have created 8 threads by 'task_scheduler_init', but I would like a certain call to 'parallel_for' to use only 3 of those threads. I would like to specify this for each algorithm call independently.

My reasons to want this:
1) Memory usage increases as the number of used threads (living task objects) increases.
2) As the number of threads increases, memory access may start to be the performance bottleneck instead of the CPU.

I thought about 2 solutions but dropped both:

1) Create separate instances of 'task_scheduler_init' for each parallel algorithm call. I can not do this, becasue some of our software components use thread local storage heavily, hence thread creation is considered resource hungry, therefore a company policy is established to create threads only once: at application startup.

2) Provide special partitioner parameter for 'parallel_for' limiting the number of ranges. I do not like this solution, because 1) the partitioner parameter was not designed for this purpose, 2) by this I would lose the ability to fine-grain load balancing, 3) this approach may not be possible for other algorithms than 'parallel_for'.

Thank for the replies

0 Kudos
2 Replies
Anton_M_Intel
Employee
260 Views

Please consider class task_arena (community preview feature)

0 Kudos
Zoltan_T_
Beginner
260 Views

Anton Malakhov (Intel) wrote:

Please consider class task_arena (community preview feature)

Thank you.
It looks what I want.

0 Kudos
Reply