Parallel computing seems to do nothing in fmincon and patternsearch

2 次查看(过去 30 天)
Hello,
I am using both fmincon and patternsearch algorithms. Note that, with regard to fmincon, I have no analytical gradient (therefore, I should use
parallelisation in this case). However, I do not understand why parallelization does not take place. How can I say this? There are 2 evidences: First, I see no reduction in computing time and second I hear no LOUDER voice in my pc (always when I use parfor I hear a lot of noise). I attach here the part of my code which is about applying parallelisation :
options=optimoptions('patternsearch',UseParallel,'true','Display','iter','OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M));
patternsearch(cost,par0,[],[],[],[],lb,ub,[],options)
options=optimoptions('fmincon',UseParallel,'on','OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M),'StepTolerance',10^(-12),'FunctionTolerance',10^(-12),'MaxFunEvals',10^8,'MaxIter',10^8);
fmincon(cost,par0,[],[],[],[],lb,ub,[],options);
Also, I see something wierd. It apears to me that matlab completely ignores UseParallel,'true'. And when I try something wrong like UseParallel,'hahahahaha' it does not throw any error message :-) (so, it seems it is not active at all).
Any idea?
Thanks in advance,
Babak

回答(1 个)

Walter Roberson
Walter Roberson 2022-8-25
You have posted
options=optimoptions('fmincon',UseParallel,'on','OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M),'StepTolerance',10^(-12),'FunctionTolerance',10^(-12),'MaxFunEvals',10^8,'MaxIter',10^8);
but you would need
options=optimoptions('fmincon','UseParallel','on','OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M),'StepTolerance',10^(-12),'FunctionTolerance',10^(-12),'MaxFunEvals',10^8,'MaxIter',10^8);
Note that parallel computing is only used in gradient estimation. If you have a low number of variables, that might not make much difference to your execution time.
  2 个评论
Mohammad Shojaei Arani
Thanks Walter,
Unfortunately, this also did not work. I have many parameters and no analytical gradient. But, I have no idea why parallel computation is in 'idle' mode. And, when I try different combinations {'UseParallel','on'}, {'UseParallel',on},{UseParallel,'on'},{'UseParallel','true'},{'UseParallel',true}, ...
matlab does not even throw an error message. Nothing works and I have no idea!!!
Raymond Norris
Raymond Norris 2022-8-25
I'm surprised to hear MATLAB doesn't throw an error. I tried two of your examples and they both threw errors
>> options=optimoptions('fmincon',UseParallel,'on','OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M),'StepTolerance',10^(-12),'FunctionTolerance',10^(-12),'MaxFunEvals',10^8,'MaxIter',10^8);
Unrecognized function or variable 'UseParallel'.
>> options=optimoptions('fmincon',{'UseParallel','on'},'OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M),'StepTolerance',10^(-12),'FunctionTolerance',10^(-12),'MaxFunEvals',10^8,'MaxIter',10^8);
Error using optimoptions (line 108)
Invalid option name specified. Provide a character vector or scalar string (such as 'Display').
A list of options can be found on the FMINCON documentation page.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by