I have a parfor loop that loops over i = 1:250, gets three values from an array according to the index. Then a calculation is being made within the parfor loop using those 3 values. I then store the results in the variables theta1, theta2, and theta3, and immediately print them to a file. I am parallelizing because the calculations take too much time, and for each index, they can be done independently. I guess MATLAB wouldn't necessarily divide the work by having workers compute independent iterations, but it could divide a given iteration between workers. In either case, would the value assignment to the variables or the printing to the file be affected by the order in which the operations are done? Is it possible that the results be printed in a different order like:
theta1 from i = 1
theta1 from i = 2
theta2 from i = 2
theta3 from i = 2
theta2 from i = 1
...
instead of the desired order, which is:
theta1 from i = 1
theta2 from i = 1
theta3 from i = 1
theta1 from i = 2
theta2 from i = 2
...
Would it be healthier to collect all the results in a cell array and then print them at the very end?
ivalue for instance. The only time I'd consider writing out in the middle is if it takes a long time and it might crash before they're all ready. Variable assignment is probs ok as long as you respect parfor's rules. - xenoclast