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

Collapsing Multiple parallel_for's

tony_az
Beginner
111 Views
I have the following pseudo-code that I'd like to optimize:
for (int i = 0; i < outerLoopCount; i++ {
parallel_for(blocked_range(0, count0, grainsize0),
*parallelForClass0);
SerialFunction0();
parallel_for(blocked_range(0, count1, grainsize1),
*parallelForClass1);
SerialFunction1();
}
The outer loop must remain serial. I'd like to combine the 2 parallel_for's into 1 call, to minimize the overhead of setting up the two parallel_for's on every iteration of the outer loop.
o Is it possible to combine the two parallel_for's so that they are only called once per outer loop iteration?
o Is it possible to combine all of the loops so that initialization is performed only once for the whole loop structure (outer loop included)?
0 Kudos
1 Reply
RafSchietekat
Black Belt
111 Views
You seem to be asking for the impossible, and it's not clear what overhead you suspect and why.

Have you tried using affiniity_partitioner with both loops (create instances outside of serial loop, use across serial-loop iterations, with each parallel_for having a separate partitioner)?
Reply