how to use fsolve in a parfor loop to reach a correct answer?

4 vues (au cours des 30 derniers jours)
S.A abtahi
S.A abtahi le 30 Oct 2021
Hi.
I have problem with parfor loop and fsolve function. when I use fsolve in a for loop it take times a lot ( at last answer correctly ), BUT when I use parfor ( and sliced variable to gather output ) its answer is incorrect. how can I use parfor and get correct answer.
part of the code:
with for :
K0=zeros(1,1,size(X1,3));
for k1=1:size(X1,3)
K0(1,1,k1)=fsolve(@(krho)det(FunChi(krho,Xrho,Xphi,N,X1,X_1,k1)),Bsw0,options);
end
with parfor :
K0=zeros(1,1,size(X1,3));
parfor k1=1:size(X1,3)
K0(1,1,k1)=fsolve(@(krho)det(FunChi(krho,Xrho,Xphi,N,X1,X_1,k1)),Bsw0,options);
end
  1 commentaire
S.A abtahi
S.A abtahi le 31 Oct 2021
it's very unaccustomed to me when I use
options = optimoptions('fsolve','Display','off','UseParallel',true);
( with parpool from the begining) in simple for loop
K0=zeros(1,1,size(X1,3));
for k1=1:size(X1,3)
K0(1,1,k1)=fsolve(@(krho)det(FunChi(krho,Xrho,Xphi,N,X1,X_1,k1)),Bsw0,options);
end
the answers become incorrect. What is happening?

Connectez-vous pour commenter.

Réponses (1)

Raymond Norris
Raymond Norris le 30 Oct 2021
It shouldn't matter, but what is UseParallel option set to? You're using parfor and then is fsolve also using parfor (which resolves to running the "inner" parfor as a for-loop in reverse, negating the need to set UseParallel).
If options has UseParallel set to true, set it to false and then run the parfor again.
  1 commentaire
S.A abtahi
S.A abtahi le 31 Oct 2021
hi
thanks but it doesn't help
I had changed my options but the answers are incorrect again.
I used the options below:
options = optimoptions('fsolve','Display','off','UseParallel',false);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Parallel Computing Fundamentals 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