Parfor possible, though iterations depend
Show older comments
Hi,
I am actually concerned with a problem that requires something like the following code, but I am wondering why this does not result in an error message:
parfor k=1:10
List = [List; ones(round(rand()*10), 5)];
end
List is a variable which size is unknown before executing the loop, since an unknown number of rows is added in each iteration.
If I am getting it right, this is supposed to produce errors when executed, since the iterations depend on each other, i.e. the number of rows in List changes with each iteration. However, for a small amount of test data this is not the case -- it seems to work. But why?
Best regards Philipp
Accepted Answer
More Answers (1)
Adam
on 22 Jul 2016
1 vote
k is not involved in your parfor loop at all so each worker will just create its own List variable and doesn't care about the fact it grows in a loop because they are all independent of each other.
If you were throwing k into the expression in some way that caused the workers to be sharing the 'List' variable then there would be a problem.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!