24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The <strong>XL</strong> <strong>Fortran</strong> compiler and the operating system provide facilities <strong>for</strong> working<br />

with floating-point exception conditions. The compiler facilities indicate the<br />

presence of exceptions by generating SIGTRAP signals. The operating-system<br />

facilities generate SIGFPE signals. Do not mix these different facilities within a<br />

single program.<br />

Compiler Features <strong>for</strong> Trapping Floating-Point Exceptions<br />

To turn on <strong>XL</strong> <strong>Fortran</strong> exception trapping, compile the program with the -qflttrap<br />

option and some combination of suboptions that includes enable. This option uses<br />

trap operations to detect floating-point exceptions and generates SIGTRAP signals<br />

when exceptions occur.<br />

-qflttrap also has suboptions that correspond to the names of the exception<br />

conditions. For example, if you are only concerned with handling overflow and<br />

underflow exceptions, you could specify something similar to the following:<br />

xlf95 -qflttrap=overflow:underflow:enable compute_pi.f<br />

You only need enable when you are compiling the main program. However, it is<br />

very important and does not cause any problems if you specify it <strong>for</strong> other files, so<br />

always include it when you use -qflttrap.<br />

An advantage of this approach is that per<strong>for</strong>mance impact is relatively low. To<br />

further reduce per<strong>for</strong>mance impact, you can include the imprecise suboption of the<br />

-qflttrap option. This suboption delays any trapping until the program reaches the<br />

start or end of a subprogram.<br />

The disadvantages of this approach include the following:<br />

v It only traps exceptions that occur in code that you compiled with -qflttrap,<br />

which does not include system library routines.<br />

v It is generally not possible <strong>for</strong> a handler to substitute results <strong>for</strong> failed<br />

calculations if you use the imprecise suboption of -qflttrap.<br />

Notes:<br />

1. If your program depends on floating-point exceptions occurring <strong>for</strong> particular<br />

operations, also specify -qfloat suboptions that include nofold and nohssngl.<br />

Otherwise, the compiler might replace an exception-producing calculation with<br />

a constant NaN or infinity value, or it might eliminate an overflow in a<br />

single-precision operation.<br />

2. The suboptions of the -qflttrap option replace an earlier technique that required<br />

you to modify your code with calls to the fpsets and fpgets procedures. You no<br />

longer require these calls <strong>for</strong> exception handling if you use the appropriate<br />

-qflttrap settings.<br />

Attention: If your code contains fpsets calls that enable checking <strong>for</strong><br />

floating-point exceptions and you do not use the -qflttrap option when<br />

compiling the whole program, the program will produce unexpected results if<br />

exceptions occur, as explained in Table 17 on page 290.<br />

Operating System Features <strong>for</strong> Trapping Floating-Point<br />

Exceptions<br />

A direct way to turn on exception trapping is to call the operating system routine<br />

fp_trap. It uses the system hardware to detect floating-point exceptions and<br />

generates SIGFPE signals when exceptions occur. <strong>Fortran</strong> definitions <strong>for</strong> the values<br />

needed to call it are in the files /usr/include/fp_<strong>for</strong>t_c.f, fp_<strong>for</strong>t_t.f, or the<br />

xlf_fp_util module.<br />

<strong>XL</strong> <strong>Fortran</strong> Floating-Point Processing 297

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!