indexing problem in parfor
이전 댓글 표시
Even having code, which should run in parralel, Matlab writes: valid indeces for 'ndLog' are restricted in PARFOR loops.
Would anybody please know, what is the issue?
Thank you very much,
Rafael
al = [30 40 50]; m = [40 50 60];
tn=10; cm=cumsum(m); S=sum(m); r=[0 1];
ndLog=zeros(sum(m)*numel(r)*numel(al)*tn,5);
parfor a = 1:tn
for aa = 1:numel(al)
for k=1:numel(r)
for mm = 1:numel(m)
ind = -m(mm)+1+cm(mm) + (k-1)*S + (aa-1)*numel(r)*S +...
(a-1)*numel(al)*numel(r)*S;
ndLog(ind,:) = [a mm aa k 1];
end
end
end
end
댓글 수: 8
Daniel M
2019년 10월 11일
You're trying to access position (a-1), but the loop for (a) does not have this information because every loop is a different Matlab instance with no information sharing. Look up how to slice a variable in parfor for more info.
Rafael Schwarzenegger
2019년 10월 11일
Daniel M
2019년 10월 11일
a is an index.
parfor a = 1:tn
Rafael Schwarzenegger
2019년 10월 11일
My mistake, it cannot index into ndLog using ind because ind is NOT an indexing variable. ind could be any value and Matlab doesn't know how to handle repeated values so it restricts them.
For example
parfor j = 1:10
ind = 1;
ndLog(ind) = 1;
end
This is a simplified version of your error. So again I ask if parallel code is even necessary?
This is one of the strangest loop implementations I've ever seen.
Shivam Prasad
2019년 10월 17일
편집: Shivam Prasad
2019년 10월 17일
Hi Rafael,
Please refer to this link regarding variables in parfor loops:- https://www.mathworks.com/help/parallel-computing/troubleshoot-variables-in-parfor-loops.html
Rafael Schwarzenegger
2019년 10월 17일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!