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

parallel_invoke calling parallel_for

Petros_Mamales
Beginner
310 Views
Hi,
Maybe a naive question, but here it is:
Would it be safe to use parallel_invoke to call functions that call parallel_for ?
TIA,
Petros

PS: the called functions contain no memory allocations - if this helps.
0 Kudos
3 Replies
RafSchietekat
Valued Contributor III
310 Views
Yes, it would.
0 Kudos
Petros_Mamales
Beginner
310 Views
Thank you very much!
Petros.
0 Kudos
RafSchietekat
Valued Contributor III
310 Views
I was going for the shortest answer possible above ("Post description must be a minimum of 14 characters"), but it seems appropriate to also say that recursive parallelism is one of the design principles of TBB, with the caveat that you shouldn't subdivide to the point that parallel overhead becomes significant, so you might want to experiment with grainsize even if you use the auto_partitioner, which seems to assume that it has all the threads for its own use and might subdivide too much when running on a highly parallel machine with lots of other instances making the same assumption.

(Added 2012-07-24) To clarify, as far as I understand auto_partitioner would not, e.g., make different initial cuts in one parallel_for() input range when in the presence of other concurrent parallel_for() calls, but when a hypothetical big input range is first divided among several parallel_for() calls each would make smaller initial cuts than with one parallel_for() on the original input range. While that is not necessarily a bad thing because the hypothetical case is just that, it provides less clearance from parallel overhead than when you would reason that there is less use for parallel slack in the individual inner loops when there are more than just a few of them and increase their effective grainsize, which would be done transparently had they been presented together to one big parallel_for(). Just something to think about...
0 Kudos
Reply