problem with parfor loop

조회 수: 5 (최근 30일)
freebil
freebil 2013년 8월 24일
I have the following code
parfor edge = 1:1000
var_node = edge_2_var_node(edge, num_of_variable_nodes)
check_node = ceil(edge_perm(edge)/dc);
H(check_node,var_node) = 1;
end
but when i try to run it, i have this "The variable H in a parfor cannot be classified." Could anyone help me? Thanks

채택된 답변

Walter Roberson
Walter Roberson 2013년 8월 24일
You will have difficulty with that set-up. parfor has to assume the possibility that two different edge_2_var_node lookups might give back the same value, leading to the possibility that different parfor cycles might be trying to write into the same H() location.
Is edge_2_var_node a function or an array? Are the edge_perm() values certain to be different by more than dc so that check_node values are certain to be unique? What can you give us that would allow it to be proven that no two H(check_node,var_node) references will be to the same location ?
  댓글 수: 13
freebil
freebil 2013년 8월 27일
Thanks for the answer. The maximum var_node value is 500000 and the maximum check_node value is 250000. Before this loop run H is sparse with zero elements and its size is 250000x500000. I appreciate your help.
Walter Roberson
Walter Roberson 2013년 8월 27일
sparse with zero elements -- so nothing in it, right? In that case you need not create it ahead of time, and can instead use
H = mod( accumarray([check_node(:), var_node(:)], 1, size(H), [], [], true), 2);
You might also want to experiment with
H = accumarray([check_node(:), var_node(:)], 1, size(H), @(X) mod(sum(X),2), [], true);
I would expect this to turn out to be slower because of the many calls to the anonymous function, but at the same time it might end up using less temporary memory.

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

추가 답변 (1개)

freebil
freebil 2013년 8월 26일
Thanks for your answer. Actually, the code is
for edge = 1:sum(num_of_edges)
var_node = edge_2_var_node(edge, num_of_variable_nodes, num_of_edges, degrees);
check_node = ceil(edge_perm(edge)/dc);
if (H(check_node,var_node) == 0)
H(check_node,var_node) = 1;
else
H(check_node,var_node) = 0;
end
end
And yes, there is possibility that (check_node,var_node) is the same more than 1 time. Is there any possibility to parfor this loop?

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by