Parfor loop with one iteration

2 vues (au cours des 30 derniers jours)
Hannah Krueger
Hannah Krueger le 19 Nov 2022
Commenté : Hannah Krueger le 23 Nov 2022
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 commentaires
Edric Ellis
Edric Ellis le 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?
Hannah Krueger
Hannah Krueger le 23 Nov 2022
Thanks for the response Edric!
The function that initiates the model does use rand in a few places, so I think that I should put rng('shuffle') at the beginning of this function.
But, Matlab isn't restarting between these different instances of the parfor loop, so why would rand be acting like it had?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by