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
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!