Parfor error: parfor variable is indexed in different ways

14 ビュー (過去 30 日間)
Bernoulli Lizard
Bernoulli Lizard 2013 年 3 月 27 日
コメント済み: Denis Menshykau 2013 年 11 月 28 日
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

採用された回答

Edric Ellis
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
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 ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by