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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Matt J
Matt J am 1 Jul. 2015
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));

Weitere Antworten (1)

Brendan Hamm
Brendan Hamm am 1 Jul. 2015
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.

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by