Problem in parallel computing (par for)

조회 수: 1 (최근 30일)
Saurav Dutta
Saurav Dutta 2020년 4월 8일
답변: Deepak Meena 2021년 7월 5일
iu_start=1;
iu_end=2;
ju_start=1;
ju_end=50;
Ki=0.05;
tic
for Kpp=iu_start:iu_start:iu_end
Kp=Kpp/1
for Kvv=ju_start:ju_start:ju_end
Kv=Kvv/10;
timespan=[0 24];
IC=eye(12,12);
initialconditions=[IC(:,1)',IC(:,2)',IC(:,3)',IC(:,4)',IC(:,5)',IC(:,6)',IC(:,7)',IC(:,8)',IC(:,9)',IC(:,10)',IC(:,11)',IC(:,12)'];
options=odeset('abstol',1e-9,'reltol',1e-9);
[t,z]=ode15s(@rRRPvvv,timespan,initialconditions);
a=z(end,:);
a1=a(:,1:12);
a2=a(:,13:24);
a3=a(:,25:36);
a4=a(:,37:48);
a5=a(:,49:60);
a6=a(:,61:72);
a7=a(:,73:84);
a8=a(:,85:96);
a9=a(:,97:108);
a10=a(:,109:120);
a11=a(:,121:132);
a12=a(:,133:144);
cc{Kpp,Kvv}=[a1',a2',a3',a4',a5',a6',a7',a8',a9',a10',a11',a12'];
egr{Kpp,Kvv}=eig(cc{Kpp,Kvv});
absegr{Kpp,Kvv}=abs(egr{Kpp,Kvv});
end
end
The above code works perfectly. Now, when I make the outer for loop par for and run it,it shows the error "Error using rRRPlen (line 20)
Error: The variable cc in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".
Please help
  댓글 수: 2
Mohammad Sami
Mohammad Sami 2020년 4월 8일
Declare cc, egr and absegr before the parfor loop.
cc = cell(2,50);
Saurav Dutta
Saurav Dutta 2020년 4월 8일
The problem still remains with the same error message

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

답변 (1개)

Deepak Meena
Deepak Meena 2021년 7월 5일
Hi ,
I tried to reproduce the error , you mentioned the code works fine without the parfor command but in my case it is giving error
Unrecognized function or variable 'rRRPvvv'.
To reproduce the issue I removed the differetial equation part and I trimmed down the code to :
iu_start=1;
iu_end=2;
ju_start=1;
ju_end=50;
Ki=0.05;
cc = cell(2,50);
egr = cell(2,50);
absegr = cell(2,50);
tic
parfor Kpp=iu_start:iu_end
Kp=Kpp/1
for Kvv=ju_start:ju_start:ju_end
Kv=Kvv/10;
a = rand(200,200);
a1=a(:,1:12);
a2=a(:,13:24);
a3=a(:,25:36);
a4=a(:,37:48);
a5=a(:,49:60);
a6=a(:,61:72);
a7=a(:,73:84);
a8=a(:,85:96);
a9=a(:,97:108);
a10=a(:,109:120);
a11=a(:,121:132);
a12=a(:,133:144);
cc{Kpp,Kvv}=[a1',a2',a3',a4',a5',a6',a7',a8',a9',a10',a11',a12'];
egr{Kpp,Kvv}=cc{Kpp,Kvv};
absegr{Kpp,Kvv}=abs(egr{Kpp,Kvv});
end
end
toc
I followed the suggestion provided by the @Mohammad Sami and it didn't throw that error.
Thanks

카테고리

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