Sun Studio 12: Fortran User's Guide

4.8 Directives

A compiler directive directs the compiler to do some special action. Directives are also called pragmas.

A compiler directive is inserted into the source program as one or more lines of text. Each line looks like a comment, but has additional characters that identify it as more than a comment for this compiler. For most other compilers, it is treated as a comment, so there is some code portability.

Sun-style parallelization directives are the default with f95 -explicitpar. To switch to Cray-style directives, use the -mp=cray compiler command-line flag. Explicit parallelization with OpenMP directives requires compiling with -openmp.

A complete summary of Fortran directives appears in Table C–1.

4.8.1 Form of Special f95 Directive Lines

f95 recognizes its own special directives in addition to those described in 1.9 Command-Line Help. These have the following syntax:

!DIR$ d1, d2, … Fixed-Form Source Free-Form Source

Thus, !DIR$ in columns 1 through 5 works for both free-form source and fixed-form source.

4.8.2 FIXED and FREE Directives

These directives specify the source form of lines following the directive line. Scope

They apply to the rest of the file in which they appear, or until the next FREE or FIXED directive is encountered. Uses Restrictions

The FREE/FIXED directives:

Example: A FREE directive.

    DO i = 1, n
        a(i) = b(i) * c(i)
    END DO

4.8.3 Parallelization Directives

A parallelization directive is a special comment that directs the compiler to attempt to parallelize the next DO loop. These are summarized in Appendix D and described in the chapter on parallelization in the Fortran Programming Guide. f95 recognizes both Sun and Cray style parallelization directives, as well as the OpenMP Fortran API directives. OpenMP parallelization is described in the OpenMP API User’s Guide.