Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
S.A abtahi
S.A abtahi el 30 de Oct. de 2021
Editada: Walter Roberson el 31 de Oct. de 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 comentario
S.A abtahi
S.A abtahi el 31 de Oct. de 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?

Iniciar sesión para comentar.

Respuestas (1)

Raymond Norris
Raymond Norris el 30 de Oct. de 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 comentario
S.A abtahi
S.A abtahi el 31 de Oct. de 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);

Iniciar sesión para comentar.

Categorías

Más información sobre Parallel Computing Fundamentals en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by