-1

I am writing a FORTRAN program for the Monte Carlo Simulation of polymer melts. While checking the value of the sum of the fractional Boltzmann weights in my Monte Carlo subroutine at certain points, I'm getting NAN after printing the variable in the subroutines. The subroutine is quite large. I'm unable to post it here. If anyone has an idea, what is the reason of getting NAN after printing the value of the variable ??. Please help as I'm unable to proceed further.

How can we overcome such a situation to avoid getting NAN ? I'm using a gfortran compiler to write my program.

  • Is there any particular reason why you're restricting yourself to FORTRAN instead of Fortran? Fortran is furnished with the intrinsic module `ieee_exceptions` to handle such floating-point exceptions. – jlokimlin Aug 11 '16 at 02:16

1 Answers1

0

If there is a NaN in your results, there is a problem (invalid arithmetic operation). You must correct it. If you can't track or have an idea where this NaN arises, I suggest you to profile your code step by step and check each of your variable until you find which one is problematic. However, the compiler can help you tracking this NaN. The flag -ffpe-trap=invalid will stop the program when a NaN occurs, the compiler should then tell you the line where the NaN arises. See the related post :Force gfortran to stop program at first NaN

Community
  • 1
  • 1
Coriolis
  • 396
  • 3
  • 10