Parfor error: parfor variable is indexed in different ways

18 vues (au cours des 30 derniers jours)
Bernoulli Lizard
Bernoulli Lizard le 27 Mar 2013
Commenté : Denis Menshykau le 28 Nov 2013
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

Réponse acceptée

Edric Ellis
Edric Ellis le 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 commentaire
Denis Menshykau
Denis Menshykau le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by