GlobalSearch inside parfor loop

3 次查看(过去 30 天)
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