max n of threads used by an algorithm

max n of threads used by an algorithm

Zoltan T.'s picture

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

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Anton Malakhov (Intel)'s picture

Please consider class task_arena (community preview feature)

Zoltan T.'s picture

Quote:

Anton Malakhov (Intel) wrote:

Please consider class task_arena (community preview feature)

Thank you.
It looks what I want.

Login to leave a comment.