Help with proper parfor
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Parallel for-Loops (parfor) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!