In most cases, the only indication that any floating-point exceptions (such as overflow, underflow, or invalid operation) have occurred is the retrospective summary message at program termination. Locating where the exception occurred requires exception trapping be enabled. This can be done by either compiling with the -ftrap=common option or by establishing an exception handler routine with ieee_handler(). With exception trapping enabled, run the program from dbx or the Sun WorkShop, using the dbx catch FPE command to see where the error occurs.
The advantage of recompiling with -ftrap=common is that the source code need not be modified to trap the exceptions. However, by calling ieee_handler() you can be more selective as to which exceptions to look at.
Example: Recompiling with -ftrap=common and using dbx:
demo% f77 -g -ftrap=common -silent myprogram.f demo% dbx a.out Reading symbolic information for a.out Reading symbolic information for rtld /usr/lib/ld.so.1 Reading symbolic information for libF77.so.3 Reading symbolic information for libc.so.1 Reading symbolic information for libdl.so.1 (dbx) catch FPE (dbx) run Running: a.out (process id 19739) signal FPE (floating point divide by zero) in MAIN at line 212 in file "myprogram.f" 212 Z = X/Y (dbx) print Y y = 0.0 (dbx)
If you find that the program terminates with overflow and other exceptions, you can locate the first overflow specifically by calling ieee_handler() to trap just overflows. This requires modifying the source code of at least the main program, as shown in the following example.
Example: Locate an overflow when other exceptions occur:
demo% cat myprog.F #include "f77_floatingpoint.h" program myprogram ... ier = ieee_handler(`set','overflow',SIGFPE_ABORT) ... demo% f77 -g -silent myprog.F demo% dbx a.out Reading symbolic information for a.out Reading symbolic information for rtld /usr/lib/ld.so.1 Reading symbolic information for libF77.so.3 Reading symbolic information for libc.so.1 Reading symbolic information for libdl.so.1 (dbx) catch FPE (dbx) run Running: a.out (process id 19793) signal FPE (floating point overflow) in MAIN at line 55 in file "myprog.F" 55 w = rmax * 200. ! Cause of the overflow (dbx) cont ! Continue execution to completion Note: IEEE floating-point exception flags raised: Inexact; Division by Zero; Underflow; ! There were other exceptions IEEE floating-point exception traps enabled: overflow; See the Numerical Computation Guide... execution completed, exit code is 0 (dbx)
To be selective, the example introduces the #include, which required renaming the source file with a .F suffix and calling ieee_handler(). You could go further and create your own handler function to be invoked on the overflow exception to do some application-specific analysis and print intermediary or debug results before aborting.