Parallel computing seems to do nothing in fmincon and patternsearch

2 vues (au cours des 30 derniers jours)
Mohammad Shojaei Arani
Mohammad Shojaei Arani le 25 Août 2022
Commenté : Raymond Norris le 25 Août 2022
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

Réponses (1)

Walter Roberson
Walter Roberson le 25 Août 2022
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 commentaires
Mohammad Shojaei Arani
Mohammad Shojaei Arani le 25 Août 2022
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 le 25 Août 2022
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by