I am using tbb::parallel_invoke to run 2 functions in parallel. Additionally the first function uses tbb::parallel_for for its algorithm. I would like to limit the number of threads used by tbb::parallel_invoke to 2 so that the tbb::parallel_for can use rest of the threads. I am not quite sure how to use tbb::task_arena or any other construct to achieve this.
Asked
Active
Viewed 289 times
0
-
1Possible duplicate of [TBB with fixed number of threads for one task, and default for others](https://stackoverflow.com/questions/25430790/tbb-with-fixed-number-of-threads-for-one-task-and-default-for-others) – Anton Jul 01 '19 at 07:17
1 Answers
0
If you only give two functions to parallel_invoke
, it will use at most two threads to execute these functions. A thread that executes the first function and calls parallel_for
within will also execute parallel_for tasks. A thread that executes the second function will run it to completion and till then it will not participate in parallel_for
; but when it completes the function it may take parallel_for
tasks as well.
In other words, unless there is something special going on in the two parallel_invoke
functions, you do not need to do anything special.

Alexey Kukanov
- 12,479
- 2
- 36
- 55
-
Thank you very much. I tested the 2 functions without parallel_invoke, one by one; i.e. running the first function which used parallel_for with all the available threads followed by the 2nd function. I got pretty good run time speed up in the first function. I then ran the 2 function using the parallel_invoke. The run time improvement in the 1st function had been reduced. This did tell me that the 2 functions in parallel_invoke had been running in parallel. Thank you further for your clarification. – user6042013 Jul 06 '19 at 17:15
-
Also, since the 2nd function took very little time, the overall run time was determined by the 1st function(masking the run time of 2nd function) – user6042013 Jul 06 '19 at 17:21