Why do the values of a NaN matrix change to zero inside a parfor?

조회 수: 1 (최근 30일)
Elias
Elias 2015년 5월 21일
편집: Elias 2015년 5월 23일
I am using parfor to compute certain values. These values only need to be computed for certain iterations. However, for the iterations that I don't need to compute them, it appears that parfor is assigning the value 'zero' to the output even though the output has been preallocated as NaN.
The behavior that I described can be replicated through this code
result_size =[1,1,3,3,3,1,1,2,1,5,7,7,5];
total_conf=prod(result_size);
t_out = NaN(result_size);
parfor i=1:total_conf
temp1 = rand();
if (temp1>0.5)
%t_out(i)=NaN;
continue;
else
t_out(i)=5;
end
end
s1=sprintf('\nNumber of elements equal to zero in the output %d',sum(t_out(:)==0));
disp(s1);
At the end of this procedure, the result is that several elements in the output have been set to zero, even though the code inside parfor does not specify such assignment. If the line
%t_out(i) = NaN;
is uncommented and the script is run again, then at the end of the procedure it is correctly reported that there are no values in the output that were set to zero.
My question is: why does parfor assigns the value 'zero' to some elements of the pre-allocated NaN array?
  댓글 수: 6
the cyclist
the cyclist 2015년 5월 22일
This definitely seems like a bug to me. I think you should submit it to support.
Elias
Elias 2015년 5월 23일
편집: Elias 2015년 5월 23일
Thanks for the response. I will submit the bug to support.

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

답변 (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