I got NaN using parfor while the same code works with for loop
2 ビュー (過去 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!