I got NaN using parfor while the same code works with for loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuestas (2)
Edric Ellis
el 30 de En. de 2018
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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!