GlobalSearch inside parfor loop

조회 수: 7 (최근 30일)
Tristan Potter
Tristan Potter 2020년 7월 2일
답변: Sean de Wolski 2020년 7월 8일
Hi everyone,
I would like to loop in parallel over a parameter of a numerical optimization problem that I'm solving via GlobalSearch. However, when I try to implement a simple parfor loop, I get the following error message:
"The function RUN might make an invalid workspace access inside the PARFOR loop."
Is there a simple workaround for this?
Thanks.

채택된 답변

Sean de Wolski
Sean de Wolski 2020년 7월 8일
Take everything inside the parfor loop and refactor it to a local or separate file function. Parfor loops should be as simple as possible:
parfor ii = 1:10
r(ii) = runGS(parameter(ii))
end
And
function r = runGS(param)
% Call global search etc.
end

추가 답변 (1개)

Gouri Chennuru
Gouri Chennuru 2020년 7월 8일
Hi Tristan,
You can go through all the information provided and thus get a clear idea about the problem you are trying to solve.
I am not so sure about the model you are working on, but these might help you with the solution and eliminate the error.
  • If your Simulink model requires access to variables contained in a .mat file, you must load these parameters in the workspace of each worker. You must do this before the parfor-loop, and after opening parpool
  • if your model also requires variables defined in the body of your MATLAB script, you must use assignin or evalin to move these variables to the base workspace of each worker, in every parfor iteration, also ensure the transparency and workspace access issues in parfor loops
You can refer to the link which provides detailed information about troubleshooting variables using parfor loops and solving variable classification issues in parfor loops.
Here is the link which guides you with different parallel processing types. In case of global search it always runs the fmincon local solver, fmincon can estimate gradients by parallel finite differences.
Hope this Helps!

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by