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

Getting SIGNALQQ to work with SIG$FPE (with Fortran main program)

kamberp
Beginner
1,201 Views
Hello,

I'm trying to implement a floating point error handler with the main program in Fortran. So I started with the example provided (GETEPTRS_S2.F90, see "Exceptions" folder in V9 examples provided at top of this board), which essentially sets up the signal handler hand_fpe for the signal SIG$FPE. The resulting behavior is the same as in my real application, namely: 1) when using RAISEQQ to force the SIG$FPE signal, the handler (and traceback) works beautifully, but if I generate a "real" divide-by-zero (as done in the example), the handler is not called (and the OS puts up an error dialog instead).

Here is my main test Fortran program (maintestfpe.f), which essentially calls the example functions (from file GETEPTRS_S2.F90). The call to FOR_SET_FPE essentially duplicates the /fpe:0 compiler option (masking to enable trapping of FPE errors), and can be commented out -- with the same result.

program main

USE DFLIB

real*4 a, b
integer status
integer(4)::FPE_STS=0, FPE_MASK=0
integer(4) set_handler
real(4) geteptrs_s2

b = 0.0

C Enable FPE trapping for overflow, div-by-zero, and invalid
FPE_MASK = FPE_M_TRAP_OVF + FPE_M_TRAP_DIV0 + FPE_M_TRAP_INV
FPE_STS = FOR_SET_FPE(FPE_MASK)

C Setup error handler
status = set_handler()

write(6,*) 'After set_handler...'

C Generate FPE error (div by zero)
a = geteptrs_s2(b)

end

Here is my compile/link statement (using Intel Fortran 8.1, but same behavior occurs using 9.0):

ifort /MD /Qsave /fpe:0 /extend_source /Zi /traceback maintestfpe.f geteptrs_s2.f90

Thanks for any suggestions!
0 Kudos
5 Replies
William_H_Intel3
Employee
1,201 Views

Try adding a print statement to print the value of variable a after the call to geteptrs_s2. See if that helps.

Thanks,

Bill

0 Kudos
kamberp
Beginner
1,201 Views
Thanks for the suggestion, unfortunately, this did not help. :)
0 Kudos
William_H_Intel3
Employee
1,201 Views
When you see the error dialog, are you running the program in the debugger or just in a console window?
0 Kudos
kamberp
Beginner
1,201 Views
Its being executed from a console window. The error dialog that comes up is a standard Windows OS termination dialog. Thanks.
0 Kudos
William_H_Intel3
Employee
1,201 Views
It sounds to me like SIGNALQQ is not establishing your handler with the C rtl. If you are comfortable coding up a call to the C rtl sigaction routine, you could try bypassing SIGNALQQ in that way.
0 Kudos
Reply