GlobalSearch inside parfor loop
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tristan Potter
le 2 Juil 2020
Réponse apportée : Sean de Wolski
le 8 Juil 2020
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.
0 commentaires
Réponse acceptée
Sean de Wolski
le 8 Juil 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
0 commentaires
Plus de réponses (1)
Gouri Chennuru
le 8 Juil 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!
0 commentaires
Voir également
Catégories
En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!