Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28600 Discussions

My FORTRAN programs do not always produce correct results (due to NaN variables).

eliopoulos
Novice
867 Views

Hi,

I have installed Windows 11, Visual Studio 2019 Community and Intel oneAPI 2021 Base and HPC Toolkit. When I run my program, sometimes it produces wrong results due to NaN variables (in the attached file I have stopped the loop to see the problem). Some other times it does not run at all. Finally, sometimes it runs and produces correct results without any issue. Is there anything I can do to solve this problem?

Best regards,

 

Dr. Elias N. Eliopoulos

University of Patras

Department of Mechanical Engineering & Aeronautics

0 Kudos
1 Solution
Arjen_Markus
Honored Contributor I
835 Views

One possible reason is that one or more variables in your program have not been set before they are used. Then the value may be anything - Fortran does not automatically initialise variables!

Other possibilities: incorrect argument lists for subroutine and function calls or violation of array bounds. In that case some random memory is accessed.

What you should do is turn on all runtime checks. A debug version of the program will definitely help with that. If you select the debug configuration in Visual Studio, you are likely to get all such checks automatically.

 

View solution in original post

0 Kudos
5 Replies
Arjen_Markus
Honored Contributor I
836 Views

One possible reason is that one or more variables in your program have not been set before they are used. Then the value may be anything - Fortran does not automatically initialise variables!

Other possibilities: incorrect argument lists for subroutine and function calls or violation of array bounds. In that case some random memory is accessed.

What you should do is turn on all runtime checks. A debug version of the program will definitely help with that. If you select the debug configuration in Visual Studio, you are likely to get all such checks automatically.

 

0 Kudos
eliopoulos
Novice
801 Views

The debug version solved my problem.

Thank you very much,

 

Dr. Elias N. Eliopoulos

0 Kudos
Arjen_Markus
Honored Contributor I
766 Views

Please be aware that the debug version may behave in a different way than the release version. Did you find the cause of the problem via the debug version or was that simply behaving in a better way? If the latter, then the difference in initialisation between debug and release has hidden the underlying bug. That is very probably an uninitialised variable somewhere in the program.

Can you tell us what you have to do to solve the problem?

0 Kudos
eliopoulos
Novice
754 Views

Hi,

the problem was that a few variables were set to have incorrect dimensions. I found out by using the debug version of the program. After fixing this problem, the debug and release version run without any issue.

Best regards,

 

Dr. Elias N. Eliopoulos

0 Kudos
Arjen_Markus
Honored Contributor I
751 Views

Ah, good to hear that - in the past I have run into such differences I described. But you found the actual errors.

0 Kudos
Reply