- The value true for UseParallel was added in R2014a. If you use an earlier version, set UseParallel to 'always'. Include the single quotes.
- In your fmincon call, do you pass options? I mean, does your call look like this:

51 views (last 30 days)

Hi All, I am performing an optimization of parameters of a Simulink model using fmincon The options I am using are the followings

options = optimoptions('fmincon'); % Start with the default options

options = optimoptions(options,'Algorithm', 'interior-point');

options = optimoptions(options,'Display', 'iter-detailed');

options = optimoptions(options,'MaxIter', 1000);

options = optimoptions(options,'PlotFcns', { @optimplotfval });

So far so good, the optimization run and arrives to a minimum with no problems at all However, as the optimization takes few hours to perform I wish to speed up the process by using parallel computing (I have a 2 core processor computer)

Then, I add the following line to the options listed above

options = optimoptions('fmincon','UseParallel',true);

Before I run the optimization with the new line of code, I set the parallel computing on manually using the following command in Matlab Command Line

parpool

Matlab gives the following message

Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.

ans =

Pool with properties:

Connected: true

NumWorkers: 2

Cluster: local

AttachedFiles: {}

IdleTimeout: 30 minutes (30 minutes remaining)

SpmdEnabled: true

I then run the optimization but I get this error

Error using optimoptions (line 114)

Invalid value for OPTIONS parameter UseParallel:

must be 'always' or 'never'.

Error in Damper_Optimization_v1 (line 134)

options = optimoptions('fmincon','UseParallel',true);

Please not the Damper_Optimization_v1 is the name of my script (where fmincon is used) and that line 134 is the line of

options = optimoptions('fmincon','UseParallel',true);

Does anybone know why I am getting this error?

I tried to use "always" instead of "true" but this did not work, I got the following error

Undefined function or variable 'always'.

Error in Damper_Optimization_v1 (line 151)

options = optimoptions('fmincon','UseParallel',always);

PS: I noted that when I add the line with the parallel computing option, the word "options" in the previous line is underlined in red and the warning message that I get for it is

The value assigned to variable 'options' might be unused

See below the rest of the code where I use fmincon

options = optimoptions('fmincon'); % Start with the default options options = optimoptions(options,'Algorithm', 'interior-point'); options = optimoptions(options,'Display', 'iter-detailed'); options = optimoptions(options,'MaxIter', 1000); options = optimoptions(options,'PlotFcns', { @optimplotfval }); %options = optimoptions('fmincon','UseParallel',true);

options = optimoptions('fmincon'); % Start with the default options options = optimoptions(options,'Algorithm', 'interior-point'); options = optimoptions(options,'Display', 'iter-detailed'); options = optimoptions(options,'MaxIter', 1000); options = optimoptions(options,'PlotFcns', { @optimplotfval }); %options = optimoptions('fmincon','UseParallel',true);

OPTIMIZATION

tic % Start stopwatch to measure elapsed time

[Optimum_Damper,fun_value,exitflag,output_details] = fmincon(...

@Objective,... % Cost Function

Damper_Parameter_Initial_Guess,...% Initial Guess

A,B,... % Damper Parameters Constrains

[],[],... % Damper Parameters Inequalities

Damper_Parameters_Lower_Bound,... % Damper Parameter Lower Bounds

Damper_Parameters_Upper_Bound,... % Damper Parameter Lower Bounds

[], ... % Non-linear conditions (NONE)

options); % Options

toc

Thanks in advance for your help

G

Alan Weiss
on 1 Apr 2014

I think there might be two issues here.

- The value true for UseParallel was added in R2014a. If you use an earlier version, set UseParallel to 'always'. Include the single quotes.
- In your fmincon call, do you pass options? I mean, does your call look like this:

[x,fval,exitflag] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

Alan Weiss

MATLAB mathematical toolbox documentation

Alan Weiss
on 9 Apr 2014

I am sorry, but I do not know if we are communicating correctly or not. I think you somehow need to define your objective function as

fun = @(Damper_Parameter)Objective_v2(Damper_Parameter,a,g,...)

where your objective function explicitly depends on the parameters a, g, etc. You say that these parameters do not change during the optimization. Then you can call

[Optim_Damper,...] = fmincon(fun,...)

and you will not have a problem. In other words, you need to write your objective function so that it passes the variables, and does not pick up variables from your workspace. Then you will be able to compute in parallel as you desire.

I do not anything about Simulink, if that is what you are using to compute your objective function. So I am sorry not to be able to advise you on how to pass parameters to Simulink. But I am certain that you can.

One more thing. I would not be surprised if you have to change some options in order to successfully optimize a Simulink model. See Optimizing a Simulation or ODE.

Alan Weiss

MATLAB mathematical toolbox documentation

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/124066-problem-using-optimoptions-with-fmincon-for-parallel-computing#comment_205562

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/124066-problem-using-optimoptions-with-fmincon-for-parallel-computing#comment_205562

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/124066-problem-using-optimoptions-with-fmincon-for-parallel-computing#comment_205623

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/124066-problem-using-optimoptions-with-fmincon-for-parallel-computing#comment_205623

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/124066-problem-using-optimoptions-with-fmincon-for-parallel-computing#comment_385890

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/124066-problem-using-optimoptions-with-fmincon-for-parallel-computing#comment_385890

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/124066-problem-using-optimoptions-with-fmincon-for-parallel-computing#comment_385892

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/124066-problem-using-optimoptions-with-fmincon-for-parallel-computing#comment_385892

Sign in to comment.