Effacer les filtres
Effacer les filtres

arrays of reduction variables

5 vues (au cours des 30 derniers jours)
Matthew
Matthew le 2 Mar 2016
Modifié(e) : Edric Ellis le 3 Mar 2016
In parallel computing toolbox, I want to create an array of reduction variables. Is it possible?
m=3; n=5;
b=zeros(m,2);
parfor i=1:n
a=[i i+1];
for j=1:m
b(j,:)=b(j,:)+j*a;
end
end
I get this result Error: The variable b in a parfor cannot be classified. See Parallel for Loops in MATLAB, "Overview".
Is there a way to make this work?
Matt

Réponse acceptée

Edric Ellis
Edric Ellis le 3 Mar 2016
Modifié(e) : Edric Ellis le 3 Mar 2016
In this case, parfor doesn't understand the fact that you're performing independent reductions on the rows of b. You can convince it by performing the update to the whole of b all at once, like so:
m=3; n=5;
b=zeros(m,2);
parfor i=1:n
a=[i i+1];
btmp = zeros(m,2);
for j=1:m
btmp(j,:) = j*a;
end
b = b + btmp;
end

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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