Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

foreach %dopar% - guarantee on order of results?

Tags:

foreach

r

By default (no .combine), foreach/%dopar% returns results in a list. Is the order of results in the list guaranteed to match the order of the loop/iteration? In other words, will the order be the same as when iterating sequentially? OR does the list get populated as a parallel task completes? Browsing the documentation, I see that there's a .inorder parameter, but it seems to only apply when using a .combine function.

like image 508
SFun28 Avatar asked Aug 29 '11 14:08

SFun28


1 Answers

When the call ends, the result of foreach will be in the same order as for a 'normal' loop. However, there is no guarantee for the order in which they 'get there': in theory (and when parallelizing, also in practice), the first item might be filled out later than the second one.

So you have no guarantee on the order of execution (e.g. progress bars or logging may be cobbled), but you can rest assured that the results will be in the order you expect them.

like image 174
Nick Sabbe Avatar answered Oct 04 '22 21:10

Nick Sabbe