I got NaN using parfor while the same code works with for loop
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone
I found I got NaN using parfor while the same code works with for-loop.
My input is very large. So I tested it with a small part of my input (only three times loop) for both for-loop and parfor loop. I got the same results. Then I used "dbstop if naninf" to debug.The code stopped at the beginning of parfor loop for parfor. While the code can give me the same results for the for-loop as if the there is no "dbstop if naninf". Finally, I tested with my entire input for both loop without "dbstop if naninf". The parfor gave me NaN to the arrays which should have values.While the for loop works fine. The part code of parfor is listed below.
parfor i=1:num_atom
tdelta_f(:,i)=xcorr(atom_for_v(:,1,i),atom_for_v(:,1,i),'biased')+xcorr(atom_for_v(:,2,i),atom_for_v(:,2,i),'biased')
+xcorr(atom_for_v(:,3,i),atom_for_v(:,3,i),'biased');
tdelta_fv(:,i)=xcorr(atom_for_v(:,4,1),atom_for_v(:,1,i),'biased')+xcorr(atom_for_v(:,5,1),atom_for_v(:,2,i),'biased')
+xcorr(atom_for_v(:,6,1),atom_for_v(:,3,i),'biased');
end
(1)It is bug of my code or bug of parfor?
(2)If my code is fine. How can I use parfor for my code in this case?
Fan Li
回答(2 个)
Edric Ellis
2018-1-30
dbstop if naninf always causes execution to stop during setup of a parfor loop. This turns out to be expected behaviour (parallel_function.m has an explicit assignment to Inf), and I believe there is nothing to worry about - either in your code, or the implementation of parfor.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!