필터 지우기
필터 지우기

Parallel computing seems to do nothing in fmincon and patternsearch

조회 수: 1 (최근 30일)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022년 8월 25일
댓글: Raymond Norris 2022년 8월 25일
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
Mohammad Shojaei Arani 2022년 8월 25일
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