Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

valid slice are restricted in PARFOR loop

2 Ansichten (letzte 30 Tage)
Allen
Allen am 1 Jun. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 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 Kommentare
Adam
Adam am 1 Jun. 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 am 5 Jun. 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?

Antworten (1)

Edric Ellis
Edric Ellis am 2 Jun. 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 Kommentar
Allen
Allen am 5 Jun. 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?

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by