Help with proper parfor

조회 수: 3 (최근 30일)
Jenn Lee
Jenn Lee 2012년 7월 23일
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.

채택된 답변

Geoff
Geoff 2012년 7월 23일
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
Jenn Lee
Jenn Lee 2012년 7월 23일
thanks! this gets rid of the parfor error. but now i have a H isn't sliced error :(

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by