필터 지우기
필터 지우기

Unrecognized variable in parfor loop

조회 수: 4 (최근 30일)
Francesco Cuomo
Francesco Cuomo 2021년 10월 11일
댓글: Francesco Cuomo 2021년 10월 22일
Hi, I'm experiencing some troubles with the parfor loop in a code with some innested for loops. It seems that a variable is not initialized in the correct way.
When trying to run this code:
parfor i=1:50
beta=linbeta(i);
HO=M_HO(alfa,beta);
for j=1:50
Id=linId(j);
if (Iy<Id && Id<Iz) && Ix~=Iy && Iy~=Iz
k=((Iy-Ix)*(Iz-Id)/((Id-Ix)*(Iz-Iy)))^0.5;
elseif (Ix<Id && Id<Iy) && Ix~=Iy && Iy~=Iz
k=((Id-Ix)*(Iz-Iy)/((Iy-Ix)*(Iz-Id)))^0.5;
else
k=0;
printf('Not SAM or LAM');
end
K=RF(0,1-k^2,1);
lintau=linspace(0,4*K,50);
%Preallocation in memory of matrices for results storage
M1=nan(length(linphi)); M2=M1; M3=M1; az1M1=M1; az2M2=M1; az3M3=M1; Mx=M1; My=M1; Mz=M1;
for m=1:length(linphi)
phi=linphi(m);
for l=1:length(lintau)
[psi,theta]=tautoangles(Id,I,we,lintau(l)); %Angles PH, not BH
alfaz1=sin(psi)*sin(theta); alfaz2=cos(psi)*sin(theta); alfaz3=cos(theta);
PN=M_BH(phi,theta,psi)*HO*ON; %M_BH(phi,theta,psi)=PH
quat=dcm2quat(PN);
M=SRT(quat(1),quat(2),quat(3),quat(4),t,prop); %In inertial axes
M_H=HO*ON*M; %In H frame
Mx(m,l)=M_H(1); My(m,l)=M_H(2); Mz(m,l)=M_H(3);
M_P=PN*M; %In principal axes
M1(m,l)=M_P(1); M2(m,l)=M_P(2); M3(m,l)=M_P(3);
az1M1(m,l)=alfaz1*M1(m,l);
az2M2(m,l)=alfaz2*M2(m,l);
az3M3(m,l)=alfaz3*M3(m,l);
end
end
az1M1_av(i,j)=mean(mean(az1M1)); az2M2_av(i,j)=mean(mean(az2M2)); az3M3_av(i,j)=mean(mean(az3M3));
Mx_av(i,j)=mean(mean(Mx)); My_av(i,j)=mean(mean(My)); Mz_av(i,j)=mean(mean(Mz));
end
end
This error occurs at the parfor line:
The source code (...) for the parfor-loop that is trying to execute on the worker could not be found.
Caused by:
Unrecognized function or variable 'k'.
Error using remoteParallelFunction (line 84)
Worker unable to find file.
Unrecognized function or variable 'k'.
It seems to me that there is no reason why the variable "k" should not be initialized before being used in the loops. I tried also to preallocate it as empty variable as soon as the parfor loop starts, but the same error occurs. Instead, without parallel computing no error occurs (but running time is incredibly long).
Can someone give me any advice? Thanks a lot in advance!
  댓글 수: 3
Abhiroop Rastogi
Abhiroop Rastogi 2021년 10월 22일
Hi Francesco,
As mentioned by Edric there is nothing wrong with assignment of "k". Can you please provide the code being executed before the "parfor" loop?
Francesco Cuomo
Francesco Cuomo 2021년 10월 22일
Hi,
thanks for your reply. I can't provide the full version of the code, but the problem was solved by evaluating the variables k and K before the parfor loop, in which K(j) is now used in the definition of the variable lintau.
Thank you.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by