Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
27 Views

Program produces NaNs with standard compilation but runs fine with -g flag

Hello Everyone,

I am running a program that solves ordinary differential equations simultaneously. I've noticed that the program produces NaNs in the output when compiled without any flags/options. However, when I add the -g flag the NaN problem disappears. I'm attaching my code here. The main program is rk4_in.f90, the other two files only provide inputs to the main program. I am working with code handed down to me so I don't have a simplified version on hand. The OS and compiler details are as follows:

OS:  Oracle Linux Server release 7.6

Compiler version: 19.0

 

Please let me know if there's any other information I can provide or diagnostics I can run.

0 Kudos
3 Replies
Highlighted
Black Belt Retired Employee
27 Views

When you use -g, you disable all optimizations. I can build and run this on Windows, and I do get the NaNs and Infinities. Running under the debugger there, the first issue I see is at:

!     Atrial pressure

      Pra = (Aa * (x(19) - Vra0) / CCsaR) &
            + (csaR * (DEXP(dsaR * (x(19) - Vra0)) - 1.d0))

This starts at line 161 of rk4_in.f90. This line gets a floating point overflow. on the fifth call to FSUB,

That's as far as I am going to go now. I suggest that you add -fpe0 to your compile options - this will cause the program to stop on overflow or NaNs. You should verify the values being used here.

0 Kudos
Highlighted
Black Belt
27 Views

Your ODE appears to involve 60 coupled differential equations. At the exit of your function subroutine, fsub, many of the derivatives are undefined:

     f(28:29), f(31:58)

You must fix this before discussing any results from your program.

A separate issue: you are using RK-4 integration with 3 million fixed steps in x. When the dependent variables are expected to vary smoothly over the interval of integration, you can do far better; if the step size is made too small, not only may your run times be excessive, the solutions may be inaccurate as well.

0 Kudos
Highlighted
Beginner
27 Views

Thank you all for your extremely helpful comments. You've given me a lot to work on. I will work on your suggestions, and I will post here if I do figure out the solution, or if I need your help again.

0 Kudos