Parfor loop with one iteration
2 views (last 30 days)
Show older comments
My overall question is:
Is there something fundamental about parfor loops that cannot deal with a single iteration (i.e. parfor ii = 1:1)?
Here is some context:
I use a parfor to simultaneously computer multiple inverse models at once (different "chains" of the same model). The number of chains I iterate through at this first step is hard coded (i.e. parfor = 1:6). After the parfor loop completes, I apply a criteria to only keep model results with acceptably low misfit to the data. I then repeat the parfor loop to redo chains with resulting high misfit models. This is done in a while loop until all models have acceptably low misfits.
The problem I am running into, is that when a single chain is high-misfit & must repeat (i.e. parfor ii = 1:1), the parfor loop will do it's thing with no obvious issue, but some of the information produced in this iteration is identical to the initial high-misfit chain. This does not seem to be an issue if the parfor loop is redoing multiple chains (i.e. parfor ii = 1:2). I understand that parfor loops are not generally intended for a single iteration loop, but because this is within a while loop (for all chains having acceptably low misfits), inevitably sometimes the parfor loop will have a single iteration.
2 Comments
Edric Ellis
on 21 Nov 2022
I know of no problems running a parfor loop with a range of size 1. Can you post any simple reproduction steps that demonstrate the problem? Are you using any random number generation routines in the body of your loop?
Answers (0)
See Also
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!