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

one bug in intel visual fortran compiler for windows version 10.1

cjfunsw
Beginner
505 Views
Hi, there,

when I was debugging the source file. I found that the intel visual fortran compiler for windows version 10.1cause error and stopwhen the denominator equals to zero. but fortran did not give a notice how this error is happened. I wrote a "write" sentence to output the value of the expression. it simply returns no output.

I think this is an often made error during coding programes. I am not sure if other users also encounter this problem.

Thank you.

Best Regards,
Jingfen Chen
0 Kudos
3 Replies
Les_Neilson
Valued Contributor II
505 Views
Can you show the code which fails ? (including the variable declarations)
Can you run a debug version of the executable? This would give you more information. Or turn on Generate Traceback for the release version.
You may also like to look at the compiler options - /fpe (floating point exceptions) for example


If your expression is a complicated one you may need to print individual variables or sub-expressions instead of the whole thing


real A,B,C.D,X,Y
A = B + C + X/Y - D

Normallyif we suspect that Y could at all be zero then we would write something like

if (abs(Y) > 0.0) then
A = B + C + X/Y - D
else
A = some appropriate valueOR return an error condition
endif

better still is to use a "tolerance"a "lowest acceptible value" : if (abs(Y) > TOL) then
This is generally know as defensive programming

Les
0 Kudos
mecej4
Honored Contributor III
505 Views
The behavior that you observed is expected. It has nothing to do with any compiler bugs. By default, the compiler produces code that provides for standard actions to take when floating point exceptions occur. If you want to track down the sources of the exceptions and fix your code to avoid them from occurring, you have to communicate that wish to the compiler by selecting suitable options.

With this test program

[fortran]program trapzerodiv
real :: x=1.0,y=0.0,z
z=x/y
write(*,*)z
end program trapzerodiv[/fortran]
compiling with the command

ifort /traceback /fpe0 zd.f90

and running the compiled program produces

[bash]forrtl: error (65): floating invalid
Image PC Routine Line Source
zd.exe 00401046 _MAIN__ 3 zd.f90
zd.exe 0045F5A3 Unknown Unknown Unknown
zd.exe 00443D58 Unknown Unknown Unknown
kernel32.dll 7C817077 Unknown Unknown Unknown[/bash]
If, on the other hand, the option /fpe0 is not used, the default floating point exception processing produces an infinity:

Infinity

If the default handling is suitable, you can use it, and your program will run to completion but may have produced many incorrect results along the way. If you enable trapping floating point exceptions, you have to fix the code to avoid such errors. How to do so depends on the nature of your program.
0 Kudos
cjfunsw
Beginner
505 Views
Hi, Les,

thank you for your suggestion. I am a newbie in coding fortran. Your suggestion is quite good.
I will try this in my coding.

Thank you so much.
Jingfen
0 Kudos
Reply