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 oth开发者_开发百科er 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.
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.
精彩评论