Parfor error: parfor variable is indexed in different ways

18 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Edric Ellis
Edric Ellis il 27 Mar 2013
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 Commento
Denis Menshykau
Denis Menshykau il 28 Nov 2013
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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by