Fortran User's Guide

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 directives are the default with f90 (and f77). To switch to Cray-style directives, use the -mp=cray compiler command-line flag.

Form of General Directive Lines

General directives have the following syntax.


!DIR$ d1, d2, ...

A general directive line is defined as follows.

The form varies for fixed-form and free-form source as follows.

Fixed-Form Source

Free-Form Source

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

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.


!DIR$ FREE
	DO i = 1, n
		a(i) = b(i) * c(i)
	END DO

Parallelization Directives

A parallelization directive is a special comment that directs the compiler to attempt to parallelize the next DO loop. Currently there is only one parallel directive, DOALL.

The DOALL directive tells the compiler to parallelize the next loop it finds, if possible.

Form of Parallelization Directive Lines

Parallel directives have the following syntax.


!MIC$ DOALL [general parameters] [scheduling parameter]

A parallelization directive line is defined as follows.

The form varies for fixed-form and free-form source as follows.

Fixed

Free

Thus, !MIC$ in columns 1 through 5 works for both free and fixed.

Example: Directive with continuation lines (DOALL directive and parameters.)


C$PAR DOALL
!MIC$&   SHARED( a, b, c, n )
!MIC$&   PRIVATE( i )
	DO i = 1, n
		a(i) = b(i) * c(i)
	END DO

Example: Same directive and parameters, with no continuation lines.


C$PAR DOALL  SHARED( a, b, c, n )  PRIVATE( i )
	DO i = 1, n
		a(i) = b(i) * c(i)
	END DO