Why do the values of a NaN matrix change to zero inside a parfor?
1 回表示 (過去 30 日間)
古いコメントを表示
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
2015 年 5 月 22 日
This definitely seems like a bug to me. I think you should submit it to support.
回答 (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!