Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

valid slice are restricted in PARFOR loop

2 visualizaciones (últimos 30 días)
Allen
Allen el 1 de Jun. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Dear All: For the sake of reducing the computation time, I decided to utilize the parallel computing toolbox, the framework of my code looks like following:
numPoints = 68;
correlations = zeros(1, numPoints);
parfor j=1:numPoints
pause(0);
if((numPoints == 68 || numPoints == 29 )&& centres(2) == 0)
if(numPoints == 68)
mirrorInds =[1,17;2,16;3,15;4,14;5,13;6,12;7,11;8,10;18,27;19,26;20,25;21,24;22,23;...
32,36;33,35;37,46;38,45;39,44;40,43;41,48;42,47;49,55;50,54;51,53;60,56;59,57;...
61,65;62,64;68,66];
else
mirrorInds = [1,2; 3,4; 5,7; 6,8; 9,10; 11,12; 13,15; 14,16; 17,18; 19,20; 23,24];
end
mirror_idx = j;
if(any(mirrorInds(:,1)==j))
mirror_idx = mirrorInds(mirrorInds(:,1)==j,2);
elseif(any(mirrorInds(:,2)==j))
mirror_idx = mirrorInds(mirrorInds(:,2)==j,1);
end
if(mirror_idx~=j & correlations(1,mirror_idx) ~= 0) (it says the correlations are restricted in the parfor loop)
...
correlations(1,j) = ...;
...
According to the sliced variable in parallel computing toolbox, there are 4 conditions on sliced variable
  1. Type of First-Level Indexing
  2. Fixed Index Listing
  3. Form of Indexing
  4. shape of array
I believe the correlations variable may already satisfy the above requirement. However, I could not understand why the matlab compiler shows that kind of information?
Could anybody give me some suggestions?
Thanks
  2 comentarios
Adam
Adam el 1 de Jun. de 2017
mirror_idx is being calculated within the parfor loop and then used as an index into the correlations matrix. As far as I remember and understand, this is not possible in a parfor loop because it doesn't know in advance what parts of the matrix are needed by each of the workers.
Allen
Allen el 5 de Jun. de 2017
Thanks for your answer, I changed my code into the following
for i = 1:numPoints
if(any(mirrorInds(:,1)==i))
mirror_idxt(i) = mirrorInds(mirrorInds(:,1)==i,2);
elseif(any(mirrorInds(:,2)==i))
mirror_idxt(i) = mirrorInds(mirrorInds(:,2)==i,1);
end
end
parfor j=1:numPoints
pause(0);
% can only do mirroring if there is no yaw
if((numPoints == 68 || numPoints == 29 )&& centres(2) == 0)
% Do not redo a mirror feature (just flip them)
mirror_idx = mirror_idxt(j);
if(mirror_idx~=j & correlations(1,mirror_idx) ~= 0)
.
.
.
It still shows the same message, I pre-compute the mirror_idx so it should be sliced. Could you give me some suggestions?

Respuestas (1)

Edric Ellis
Edric Ellis el 2 de Jun. de 2017
Adam's comment is correct. The parfor machinery cannot prove that your loop iterations are order-independent because you're indexing correlations in two different ways - you're reading from correlations(1,mirror_idx) as well as writing to correlations(1,j).
So, in this case you do not have a "fixed index listing" - you've got two different index listings. Also, correlations(1, mirror_idx) alone could never be "sliced" since you're not using the loop variable as one of the indices.
  1 comentario
Allen
Allen el 5 de Jun. de 2017
Thanks for your answer, I changed my code into the following
for i = 1:numPoints
if(any(mirrorInds(:,1)==i))
mirror_idxt(i) = mirrorInds(mirrorInds(:,1)==i,2);
elseif(any(mirrorInds(:,2)==i))
mirror_idxt(i) = mirrorInds(mirrorInds(:,2)==i,1);
end
end
parfor j=1:numPoints
pause(0);
% can only do mirroring if there is no yaw
if((numPoints == 68 || numPoints == 29 )&& centres(2) == 0)
% Do not redo a mirror feature (just flip them)
mirror_idx = mirror_idxt(j);
if(mirror_idx~=j & correlations(1,mirror_idx) ~= 0)
.
.
.
It still shows the same message, I pre-compute the mirror_idx so it should be sliced. Could you give me some suggestions?

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by