Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
parallel computing with fmincon

Subject: parallel computing with fmincon

From: kamuran turksoy

Date: 20 Nov, 2011 21:05:15

Message: 1 of 3

Hi everybody

I have a nonlinear constraint minimization problem and i try to solve it with fmincon, but since i have 238 variable fmincon works very slow. To seed up i want to use parallel computing. In matlab help forums i found:

matlabpool open 2
options = optimset('UseParallel','always');
fmincon(...,options)
matlabpool close

but whenever i use this way it gives error as:

??? Error using ==> parallel_function at
598
Error in ==> objective at 12
Matrix dimensions must agree.

Error in ==> parfinitedifferences at 110
    parfor(gcnt=1:nVar)
    
Error in ==> nlconst at 355
                [gf,gnc(:,nonlIneqs_idx),gnc(:,nonlEqs_idx),numEvals]
                = ...

Error in ==> fmincon at 724
    [X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...


When i remove matlabpool open 2 and matlabpool close, the algorithm works without error but in that case i noticed it does not work as parallel.

Can anybody help to figure out why i am getting this error?

Regards

Subject: parallel computing with fmincon

From: kamuran turksoy

Date: 20 Nov, 2011 21:52:13

Message: 2 of 3

I just noticed what is the problem. In my objective function i have multiple variables. I use only variable that optimization depends on, i define others as global variable. I found that in optimization iteration these global variables first gets their real value but after second iteration inside fmincon they becomes zero and that's why it gives that dimension problem, and i have no idea why after first iteration these globals becomes zero?

Subject: parallel computing with fmincon

From: Alan Weiss

Date: 21 Nov, 2011 15:27:20

Message: 3 of 3

On 11/20/2011 4:52 PM, kamuran turksoy wrote:
> I just noticed what is the problem. In my objective function i have
> multiple variables. I use only variable that optimization depends on, i
> define others as global variable. I found that in optimization iteration
> these global variables first gets their real value but after second
> iteration inside fmincon they becomes zero and that's why it gives that
> dimension problem, and i have no idea why after first iteration these
> globals becomes zero?

As explained here:
http://www.mathworks.com/help/toolbox/optim/ug/briutum.html#bri1tw7
and also here:
http://www.mathworks.com/help/toolbox/distcomp/bq__cs7-1.html#brdqrmd-1
you cannot use global variables with the parfor parallel computing
construct, which is what optimization toolbox uses.

Sorry.

Alan Weiss
MATLAB mathematical toolbox documentation

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us