Parfor error: parfor variable is indexed in different ways
조회 수: 14 (최근 30일)
이전 댓글 표시
I am trying to convert my code to run in parallel, but I get an error when I use the parfor : "in a parfor loop, variable is indexed in different ways". I can not understand, how is this being indexed in different ways? The order that each iteration is completed does not matter, and each iteration is completely independent.
parfor g = 1:ng
[A] = function(g)
B(g, :, 1) = mean( A(:,:) );
B(g, :, 2) = std( A(:,:) );
thanks end
댓글 수: 0
채택된 답변
Edric Ellis
2013년 3월 27일
Your variable 'B' has two different lists of subscripts - to run in PARFOR, you need to provide precisely the same list of subscripts. You can fix this by converting your expression to be a single indexed assignment. You need something like this
numColsInB = size(B,2);
...
parfor ...
newVals = [mean(A(:, :)), std(A(:, :))];
B(g, :, 1:2) = reshape(newVals, 1, numColsInB, 2);
end
댓글 수: 1
Denis Menshykau
2013년 11월 28일
Dear Edric,
I have a similar problem. Following your example I created the following simple test:
nPar=10;
data=zeros(nPar,2);
parfor n=1:nPar
v1=n^2;
v2=n^2-1;
newV=[v1, v2];
data(n,1:2)=reshape(newV,1,2);
end
however matlab generates an error: "Error using testParfor Error: The variable data in a parfor cannot be classified."
What is the problem?
Regards, Denis
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!