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

floating point exceptions

jaroberts2
Beginner
1,419 Views
Hi, I just installed the latest Intel Fortran compiler (noncommercial) on a Ubuntu 9.04 system (running w/ AMD64). I'm pretty new to ifort, and I'm not sure why I'm unable to stop floating point exceptions.

Example program:

program test
implicit none
real :: a, b
a = 0.0
b = 0.0
print *, a/b
end progam test


If I compile this using
>>$ ifort -fpe0 test.f90 -o testx
I would expect execution to halt and declare an exception, but it doesn't and simply prints NaN.

Any suggestions?
0 Kudos
4 Replies
TimP
Honored Contributor III
1,419 Views
Quoting - jaroberts2

program test
implicit none
real :: a, b
a = 0.0
b = 0.0
print *, a/b
end progam test


I would expect execution to halt and declare an exception, but it doesn't and simply prints NaN.

In this case, you would expect the compiler to evaluate a/b as NaN (non-signaling?), regardless of any run time behavior you attempt to set.
In certain past Unix-like operating systems, you might capture run-time exceptions without invoking IEEE_EXCEPTIONS, by running under debugger with specific options set, but I fear there is no exact equivalent available in linux. Anyway, you would be searching for exceptions raised at run time, not at compile time.
0 Kudos
jaroberts2
Beginner
1,419 Views
Quoting - tim18
In this case, you would expect the compiler to evaluate a/b as NaN (non-signaling?), regardless of any run time behavior you attempt to set.
In certain past Unix-like operating systems, you might capture run-time exceptions without invoking IEEE_EXCEPTIONS, by running under debugger with specific options set, but I fear there is no exact equivalent available in linux. Anyway, you would be searching for exceptions raised at run time, not at compile time.

Ah, I should have been a bit clearer. I expected the exception (NaN) at run time. I get the expected behavior when I compile the same using gfortran with the -ffpe-trap=invalid flag. I did test the same code on another linux machine (I'm not sure of the exact breed nor the exact ifort version) and it also gave the exception.
0 Kudos
TimP
Honored Contributor III
1,419 Views
Quoting - jaroberts2

I expected the exception (NaN) at run time. I get the expected behavior when I compile the same using gfortran with the -ffpe-trap=invalid flag. I did test the same code on another linux machine (I'm not sure of the exact breed nor the exact ifort version) and it also gave the exception.
Did you perhaps not set -O when you used gfortran? Remember that ifort defaults to -O2, and there is aggressive compile-time constant propagation, while gfortran defaults to -O0.
0 Kudos
jaroberts2
Beginner
1,419 Views
Quoting - tim18
Did you perhaps not set -O when you used gfortran? Remember that ifort defaults to -O2, and there is aggressive compile-time constant propagation, while gfortran defaults to -O0.
I had included -O0 earlier, and it didn't help. I just verified that it does not change my situation.

Is there anything else I might be missing?
0 Kudos
Reply