MATLAB: GlobalSearch inside parfor loop

parfor

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.

Best Answer

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
Related Question