Sliced variable index problem for parfor

2 visualizaciones (últimos 30 días)
Jose Ramon Silos de Alba
Jose Ramon Silos de Alba el 10 de Dic. de 2017
Comentada: Walter Roberson el 11 de Dic. de 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

Respuesta aceptada

Matt J
Matt J el 10 de Dic. de 2017
Editada: Matt J el 10 de Dic. de 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 comentarios
Matt J
Matt J el 10 de Dic. de 2017
You're welcome, but please click "Accept" to close the question.
Walter Roberson
Walter Roberson el 11 de Dic. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by