| Cray Fortran CompilerTM Commands and Directives Reference Manual - S-3901-51 | ||
|---|---|---|
| Prev Section | Chapter 4. Cray Fortran Compiler Directives | Next Section |
The following directives control aspects of scalar optimization:
INTERCHANGE and NOINTERCHANGE
NOSIDEEFFECTS
SUPPRESS
The following subsections describe these directives.
The loop interchange control directives specify whether or not the order of the following two or more loops should be interchanged. These directives apply to the loops that they immediately precede.
The formats of these directives are as follows:
|
The compiler reorders the loops such that the loop with do_variable1 is outermost, then loop do_variable2, then loop do_variable3.
The NOINTERCHANGE directive inhibits loop interchange on the loop that immediately follows the directive.
Example: The following code has an INTERCHANGE directive:
!DIR$ INTERCHANGE (I,J,K)
DO K = 1,NSIZE1
DO J = 1,NSIZE1
DO I = 1,NSIZE1
X(I,J) = X(I,J) + Y(I,K) * Z(K,J)
ENDDO
ENDDO
ENDDO |
The following code results when the INTERCHANGE directive is used on the preceding code:
!DIR$ INTERCHANGE (I,J,K)
DO I = 1,NSIZE1
DO J = 1,NSIZE1
DO K = 1,NSIZE1
X(I,J) = X(I,J) + Y(I,K) * Z(K,J)
ENDDO
ENDDO
ENDDO |
The NOSIDEEFFECTS directive allows the compiler to keep information in registers across a single call to a subprogram without reloading the information from memory after returning from the subprogram. The directive is not needed for intrinsic functions and VFUNCTIONs.
NOSIDEEFFECTS declares that a called subprogram does not redefine any variables that meet the following conditions:
Local to the calling program
Passed as arguments to the subprogram
Accessible to the calling subprogram through host association
Declared in a common block or module
Accessible through USE association
The format of this directive is as follows:
!DIR$ NOSIDEEFFECTS f [, f ] ... |
| f | Symbolic name of a subprogram that the user is sure has no side effects. f must not be the name of a dummy procedure, module procedure, or internal procedure. |
A procedure declared NOSIDEEFFECTS should not define variables in a common block or module shared by a program unit in the calling chain. All arguments should have the INTENT(IN) attribute; that is, the procedure must not modify its arguments. If these conditions are not met, results are unpredictable.
The NOSIDEEFFECTS directive must appear in the specification part of a program unit and must appear before the first executable statement.
The compiler may move invokations of a NOSIDEEFFECTS subprogram from the body of a DO loop to the loop preamble if the arguments to that function are invariant in the loop. This may affect the results of the program, particularly if the NOSIDEEFFECTS subprogram calls functions such as the random number generator or the real-time clock.
The effects of the NOSIDEEFFECTS directive are similar to those that can be obtained by specifying the PURE prefix on a function or a subroutine declaration. For more information on the PURE prefix, see Fortran Language Reference Manual, Volume 2.
The SUPPRESS directive suppresses scalar optimization for all variables or only for those specified at the point where the directive appears. This often prevents or adversely affects vectorization of any loop that contains SUPPRESS. The format of this directive is as follows:
!DIR$ SUPPRESS [ var [, var ] ... ] |
| var | Variable that is to be stored to memory. If no variables are listed, all variables in the program unit are stored. If more than one variable is specified, use a comma to separate vars. |
At the point at which !DIR$ SUPPRESS appears in the source code, variables in registers are stored to memory (to be read out at their next reference), and expressions containing any of the affected variables are recomputed at their next reference after !DIR$ SUPPRESS. The effect on optimization is equivalent to that of an external subroutine call with an argument list that includes the variables specified by !DIR$ SUPPRESS (or, if no variable list is included, all variables in the program unit).
SUPPRESS takes effect only if it is on an execution path. Optimization proceeds normally if the directive path is not executed because of a GOTO or IF.
Example:
SUBROUTINE SUB (L)
LOGICAL L
A = 1.0 ! A is local
IF (L) THEN
!DIR$ SUPPRESS ! Has no effect if L is false
CALL ROUTINE()
ELSE
PRINT *, A
END IF
END |
In this example, optimization replaces the reference to A in the PRINT statement with the constant 1.0, even though !DIR$ SUPPRESS appears between A=1.0 and the PRINT statement. The IF statement can cause the execution path to bypass !DIR$ SUPPRESS. If SUPPRESS appears before the IF statement, A in PRINT * is not replaced by the constant 1.0.
| Prev Section | Table of Contents | Title Page | Index | Next Section |
| Inlining Directives | Up one level | Local Use of Compiler Features |