GlobalSearch inside parfor loop

6 views (last 30 days)
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.

Accepted Answer

Sean de Wolski
Sean de Wolski on 8 Jul 2020
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

More Answers (1)

Gouri Chennuru
Gouri Chennuru on 8 Jul 2020
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!

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!