Parfor possible, though iterations depend
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Adam
el 22 de Jul. de 2016
1 voto
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.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!