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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

v<br />

Code that might cause an exception is not moved unless the exception is certain<br />

to occur anyway. In the following example, the program could evaluate the<br />

expression N/K be<strong>for</strong>e the loop because the result is the same <strong>for</strong> each iteration of<br />

the loop:<br />

DO 10 J=1,N<br />

...<br />

IF (K .NE. 0) M(J)=N/K<br />

...<br />

10 END<br />

v<br />

v<br />

However, it is not moved because K might be 0, and computing N/K results in<br />

an exception where none occurs in the unoptimized program.<br />

The rules <strong>for</strong> IEEE arithmetic are followed more closely than otherwise. 3 For<br />

example, X+0.0 is not folded to X, because IEEE rules require that -0.0+0.0 be 0,<br />

making X+0 equal to -X in this one case.<br />

Floating-point calculations are not considered associative. For example, <strong>XL</strong><br />

<strong>Fortran</strong> evaluates X*Y*Z left-to-right, even though the program might already<br />

have computed Y*Z, because the results might not be identical.<br />

As the optimization level increases, these restrictions are relaxed where there is an<br />

opportunity <strong>for</strong> a per<strong>for</strong>mance improvement:<br />

v<br />

v<br />

v<br />

Calculations like N/K in the previous example and floating-point operations may<br />

be moved or rescheduled because they are unlikely to cause exceptions.<br />

IEEE con<strong>for</strong>mance is not en<strong>for</strong>ced <strong>for</strong> rules that are unlikely to be needed. The<br />

sign of zero might not be correctly preserved, as in the preceding example.<br />

However, this might only be a problem in an extreme case, such as multiplying<br />

the wrongly signed zero by infinity and ending up with an infinity of the wrong<br />

sign. Floating-point operations that might cause an exception may be moved,<br />

rescheduled, or processed so they do not produce an exception.<br />

Floating-point expressions might be reassociated, so that results might not be<br />

identical.<br />

When you specify the highest levels of optimization, <strong>XL</strong> <strong>Fortran</strong> assumes that you<br />

are requesting speed even at the possibility of some risk, as already explained. If<br />

you want as much optimization as possible without the resulting risk, you must<br />

add the -qstrict compiler option.<br />

The early <strong>XL</strong> family of compilers adopted a conservative approach to optimization.<br />

This was intended to make an optimized program work exactly the same as an<br />

unoptimized one, even in extreme cases unlikely to occur in real life. For example,<br />

the array reference A(N) might not be optimized, because N might be a huge<br />

number so that the program causes a segmentation violation when the address is<br />

referenced, and this behavior would be “preserved”. With the industry in general<br />

favoring a less conservative approach, <strong>XL</strong> <strong>Fortran</strong>’s highest optimization levels<br />

now emphasize per<strong>for</strong>mance over identical execution between optimized and<br />

unoptimized programs.<br />

The different levels of the -O option incorporate various optimization techniques<br />

that are expected to improve per<strong>for</strong>mance <strong>for</strong> many different kinds of programs.<br />

The specialized optimization options, such as -qipa, -qhot, and -Q, can improve<br />

per<strong>for</strong>mance in some kinds of programs but degrade it in others. There<strong>for</strong>e, they<br />

may require experimentation to determine whether they are appropriate <strong>for</strong> any<br />

given program.<br />

3. If IEEE compliance is a concern <strong>for</strong> you, you should also specify either the -qfloat or -qstrict option.<br />

306 <strong>XL</strong> <strong>Fortran</strong> <strong>Enterprise</strong> <strong>Edition</strong> <strong>for</strong> <strong>AIX</strong> : User’s <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!