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

1 view (last 30 days)
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 Comments
the cyclist
the cyclist on 22 May 2015
This definitely seems like a bug to me. I think you should submit it to support.
Elias
Elias on 23 May 2015
Edited: Elias on 23 May 2015
Thanks for the response. I will submit the bug to support.

Sign in to comment.

Answers (0)

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!