Can parfor be used in this context?

1 view (last 30 days)
Hi,
i use a for loop to fill the columns of a list sequentally and the way the next column is filled depends on the content of the current column. For speed i'd like to use parfor, but the script shows a red warning saying "Valid indices for (name of list) are restricted in parfor loops", which I don't understand how to adress. This Warning also shows up if i simply use indices like (1,1,1). Can I use parfor in a context where the second iteration depends on the results of the first iteration or does the warning tells me something else?

Accepted Answer

Jan
Jan on 17 Jun 2022
"Can I use parfor in a context where the second iteration depends on the results of the first iteration."
No, you can't for obvious reasons. How could a work be done in parallel, if the process depends on the former results? Imagine the situation physically, e.g. two bakerman with one knead the dough while the other one is shaping the bread. The second one has to wait until the first one is ready.
For more explicit tips, post your code here instead of explaining, what it should do.
  4 Comments
Edric Ellis
Edric Ellis on 20 Jun 2022
@Jan hm, I see what you mean. You and I can see that you're trying to perform a reduction operation, but you didn't match the pattern. The parfor machinery only sees that you're assigning (without indexing) to dummy, you're not matching the "reduction variable" pattern, and is forced to conclude: "Aha! That must be a temporary variable". And then it thinks "Oh dear, the temporary variable is being used before being assigned, that is a problem". There's more on supported parfor reductions in the doc.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!