Sliced variable index problem for parfor
3 views (last 30 days)
Show older comments
Jose Ramon Silos de Alba
on 10 Dec 2017
Commented: Walter Roberson
on 11 Dec 2017
Hi, I'm trying to select some Items from a 4D matrix using a parfor, but I get the sliced variables error, can't figure what is wrong. The indexing is clearly independent for each loop, all values in Idx_ValidGM are different.
for ii=1:size(NumStories,1)
X_index = (ii-1)*size(T_Obj,2)*size(Q,1)*(NumGM - size(Discard,1));
for jj=1:size(T_Obj,2)
X_index = X_index + (jj-1)*size(Q,1)*(NumGM - size(Discard,1));
for kk=1:size(Q,1)
X_index = X_index + (kk-1)*(NumGM - size(Discard,1));
parfor ll = 1:NumGM
if Idx_ValidGM(ll) > 0
Index = X_index + Idx_ValidGM(ll);
Y_in(Index) = MaxMuMat(ii,jj,kk,ll);
end
end
end
end
end
0 Comments
Accepted Answer
Matt J
on 10 Dec 2017
Edited: Matt J
on 10 Dec 2017
all values in Idx_ValidGM are different
PARFOR has no way of knowing that. In any case, there is a far easier solution not involving parfor:
Lidx=Idx_ValidGM(ll) > 0;
IdxValid=Idx_ValidGM(Lidx);
data=MaxMuMat(:,:,:,Lidx);
for ii=1:size(NumStories,1)
X_index = (ii-1)*size(T_Obj,2)*size(Q,1)*(NumGM - size(Discard,1));
for jj=1:size(T_Obj,2)
X_index = X_index + (jj-1)*size(Q,1)*(NumGM - size(Discard,1));
for kk=1:size(Q,1)
X_index = X_index + (kk-1)*(NumGM - size(Discard,1));
Index=X_index + IdxValid;
Y_in(Index)=data(ii,jj,kk);
end
end
end
3 Comments
Walter Roberson
on 11 Dec 2017
"all values in Idx_ValidGM are different"
parfor does not even know that the values are all positive. It cannot prove that all of the output locations are unique.
More Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!