Parfor loop with one iteration

조회 수: 2 (최근 30일)
Hannah Krueger
Hannah Krueger 2022년 11월 19일
댓글: Hannah Krueger 2022년 11월 23일
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
Edric Ellis
Edric Ellis 2022년 11월 21일
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 2022년 11월 23일
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?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by