|
[Sponsors] |
November 5, 2018, 10:14 |
Trying to resolve -NaN problem
|
#1 |
New Member
Floyd Pfeffer
Join Date: Nov 2018
Location: Portugal
Posts: 3
Rep Power: 7 |
I am writing a program with Lahey/Fujitu Fortran 95. I have a subroutine which calls another subroutine. On the first call to this subroutine, it give a -NaN (not a number) answer. It only does this on the first time the subroutine is called. All subsquent calls return the correct answer. I have checked for a divide by zero which usually results in a -NaN but can't see it. Here is the weird part. When I put a screen print (Print *, var) in the subroutine, the problem goes away?? When I remove the print statement the problem comes back.
Has anyone ever had this kind of problem? What other things can cause a -NaN error? Any help would be appreciated. Floyd Pfeffer |
|
November 5, 2018, 10:38 |
|
#2 |
Super Moderator
|
Some more things to check
Check for uninitialized variables check for accessing an array outside its range sqrt of a negative number |
|
November 5, 2018, 11:54 |
|
#3 | |
Senior Member
Join Date: Dec 2017
Posts: 153
Rep Power: 8 |
Quote:
Edit: sorry just realized you have already excluded this option. Are you using implicit none statment to exclude badly declared variables? |
||
November 5, 2018, 12:37 |
|
#4 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,783
Rep Power: 71 |
The first thing to do is to compile without any optimization and using the debug options, check bounds array and so on. The run-time error should also provide the infos about the line of your error. While NaN is a signal of a division by zero, it could be do to a wrong access to the memory location.
|
|
November 5, 2018, 12:54 |
|
#5 |
Senior Member
Join Date: Dec 2017
Posts: 153
Rep Power: 8 |
Filippo has provided a good answer as usual.
In your makefile add the following flags: -oO -fbounds-check In this way the compiler avoids vectorization and it gives you an error if you are using an index out of bounds. It looks to me an error that you can fix just commenting the code and running it line by line to find out your issue. If you want to use a machinegun against a little ant, then valgrind is what you are looking for. |
|
November 7, 2018, 04:01 |
Success
|
#6 |
New Member
Floyd Pfeffer
Join Date: Nov 2018
Location: Portugal
Posts: 3
Rep Power: 7 |
Taking the optimization off solved the problem. Thanks to all that helped
Floyd Pfeffer |
|
November 7, 2018, 04:09 |
|
#7 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,783
Rep Power: 71 |
||
November 7, 2018, 04:22 |
|
#8 | |
Senior Member
Join Date: Dec 2017
Posts: 153
Rep Power: 8 |
Quote:
Try to download "valgring" and run the code until that point (valgrind --leak-check=yes myprog ). You shuold be able to find out more about your error. Otherwise use the brute force and comment all the routine that is giving you the NaN and sequentially uncomment the lines and the code to find out the one that is giving you problems. It is a time consuming option, but can be effective if your routine is not too long. |
||
November 7, 2018, 07:50 |
|
#9 |
Super Moderator
|
Yes, dont ignore such errors. Changing optimization level is not the solution.
Try compiling/running with other compilers like gfortran. Use flags -Wall and also -fbounds-check which was suggested before. Look at all warnings and convince yourself they are not errors. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mesh& steptime independant: conduction-convection problem | Fati1 | Main CFD Forum | 1 | October 28, 2018 13:52 |
problem during mpi in server: expected Scalar, found on line 0 the word 'nan' | muth | OpenFOAM Running, Solving & CFD | 3 | August 27, 2018 04:18 |
the problem of the application(icoFoam) | touff00 | OpenFOAM Running, Solving & CFD | 1 | October 18, 2015 06:12 |
F-packing problem | Streamlet | FLOW-3D | 4 | April 29, 2011 03:41 |
Cells with t below lower limit | Purushothama | Siemens | 2 | May 31, 2010 21:58 |