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.
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.
Your ODE appears to involve 60 coupled differential equations. At the exit of your function subroutine, fsub, many of the derivatives are undefined:
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.
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.