Help with proper parfor

3 vues (au cours des 30 derniers jours)
Jenn Lee
Jenn Lee le 23 Juil 2012
I am trying to parallize two of my for-loops and run it on a remote cluster.
I am using matlabpool open local 12 at the beginning with matlabpool close at the end. The problem I am running into is that my parfor-loop cannot use my matric properly and I am not sure how I would rewrite it so that it works.
H = hadamard(n);
H = [H;-H];
P = setdiff(P,H,'rows');
[r,c] = size(P);
A = zeros(n,r);
parfor i=1:r
for j=1:n
d = P(i,:) + H(j,:);
A(j,i) = sum(d(:) ~= 0);
end
end
and:
u2Had = cell(2,r);
parfor i =1:r
u2Had{1,i} = min(A(:,i));
MinHadIndex = find(A(:,i) == u2Had{1,i});
u2Had{2,i} = MinHadIndex;
end
Those are the two segments of the code I am trying to parallize. Any help is much appreciated and if I need to add anymore information please ask.

Réponse acceptée

Geoff
Geoff le 23 Juil 2012
You can't write to a parallel-segmented matrix in the inner loop. Try this:
parfor i=1:r
col = zeros(n,1);
for j=1:n
d = P(i,:) + H(j,:);
col(j) = sum(d(:) ~= 0);
end
A(:,i) = col;
end
Not quite sure about the cell-array usage. If there's an issue there, it's likely to be because the cell-array has two rows instead of one. If you expect that call to find to only return 1 value, then state it explicitly: find(..., 1, 'first') and use a matrix for u2Had.
  1 commentaire
Jenn Lee
Jenn Lee le 23 Juil 2012
thanks! this gets rid of the parfor error. but now i have a H isn't sliced error :(

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