필터 지우기
필터 지우기

Parfor: Variable (Ind) is not sliced; Recommendations about my code?

조회 수: 1 (최근 30일)
Christoforos Rekatsinas
Christoforos Rekatsinas 2015년 7월 1일
답변: Matt J 2015년 7월 1일
I have the below lines of code and i want to make it with parfor. But i get the folloing message: Parfor cannot run due to the way Ind is used, and the it has minor corrections about the variables using the vector Ind that are not sliced. Any suggestions?
parfor iel=1:nelm
inadd=0;
Hnodes=Element_Table(iel,1:tot_Nods);
for il=1:z_nodes
for i_ind=1:tot_Nods;
hn=Hnodes(i_ind);
ielN=Element_Table(iel,i_ind+(il-1)*tot_Nods);
if (ielN>mxH && ielN<mnH);
DOFS=middofs; else DOFS=HalfDofs; end
[posf, poslf]=locF(il, z_nodes, totnodes, hn);
DoFs=1+inadd:DOFS+inadd; idofs=1:DOFS;
Ind(DoFs)=idofs+posf+poslf;
inadd=inadd+DOFS;
end
end
Unv(posel,1)=Un(Ind);
Ubv(posel,1)=Ub(Ind);
Kvn(Ind)=Kvn(Ind)+ K*Unv;
Mvn(Ind)=Mvn(Ind)+ M*Unv;
Mvb(Ind)=Mvb(Ind)+ M*Ubv;
end

채택된 답변

Matt J
Matt J 2015년 7월 1일
Ind looks like a temporary variable and therefore needs to be created inside the parfor loop. Also, this kind of accumulation
Kvn(Ind)=Kvn(Ind)+ K*Unv;
Mvn(Ind)=Mvn(Ind)+ M*Unv;
Mvb(Ind)=Mvb(Ind)+ M*Ubv;
has no obvious parallel structure. Perhaps you meant the following
Kvn(el,Ind)= K*Unv;
Mvn(el,Ind)= M*Unv;
Mvb(el,Ind)= M*Ubv;
and then later after the parfor loop,
Kvn=squeeze(sum(Kvn,1));
Mvn=squeeze(sum(Mvn,1));
Mvb=squeeze(sum(Mvb,1));

추가 답변 (1개)

Brendan Hamm
Brendan Hamm 2015년 7월 1일
Often times when you run into an error like this, your easiest solution will be to take the inside of the parfor loop and turn it into a function.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by