Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using MultiStart with parallelization (-10 output flag)

223 views
Skip to first unread message

Marcelo Silva

unread,
Jan 29, 2013, 7:33:07 AM1/29/13
to
Hello all,

I am trying for the first time to use parallelization in Matlab to obtain a set of parameters that minimise a nonlinear least squares problem. I am using lsqnonlin like this:

matlabpool open local 4

lb = [4,0.5];
ub = [13,5];
p0 = lb + rand*(ub-lb);

ObjectiveFunction = @(par)cost_ctmi(time,meas,exp_cond,par);
problem = createOptimProblem('lsqnonlin','objective',ObjectiveFunction,...
'x0',p0,'lb',lb,'ub',ub);

ms = MultiStart('UseParallel','always');
[par_ctmi,~] = run(MultiStart,problem,100);

My objective function is nested:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function res = cost_ctmi(time,meas,exp_cond,par_ctmi)

npoints = length(time);
ncond = size(exp_cond,1);

Yout = zeros(npoints,ncond);

for i=1:ncond
[~,Yout(:,i)] = ctmi(time,exp_cond(i,:),par_ctmi);
end

% Compute cost function
res = meas-Yout; k = numel(res);
res = reshape(res,k,1);

matlabpool close
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

So, in the end, the objective function delivers a vector with all the residuals for each set of experimental conditions to be minimised by lsqnonlin.

The problem is that although this works without 'UseParallel', when 'UseParallel' is set to 'always', it gives a -10 exit flag error: Failures encountered in user-provided functions.
I have already tried also fmincon with the ObjectiveFunction returning a scalar value (sum of squared residuals), but this error persists.

Do you have any idea for the solution?

Kind regards

Alan_Weiss

unread,
Jan 29, 2013, 8:04:28 AM1/29/13
to
I wonder if you are running into one of the problems described here:
http://www.mathworks.com/help/distcomp/programming-considerations.html#brdqrmd-1
"Nested Functions

The body of a parfor-loop cannot make reference to a nested function
<../matlab/matlab_prog/nested-functions.html>. However, it can call a
nested function by means of a function handle."

I really don't know if this is the problem, but perhaps you can rewrite
your objective to satisfy that limitation and see if it helps.

Good luck,

Alan Weiss
MATLAB mathematical toolbox documentation

Marcelo Silva

unread,
Jan 29, 2013, 10:05:11 AM1/29/13
to
Alan_Weiss <awe...@mathworks.com> wrote in message <ke8hcs$t4a$1...@newscl01ah.mathworks.com>...
Thank you Alan for your help. I have already solved the problem, I was declaring a global variable in one of the functions that I was calling.

KInd regards,
Marcelo
0 new messages