Intel® Fortran Compiler 16.0 User and Reference Guide

PREFETCH and NOPREFETCH

General Compiler Directives: PREFETCH hints to the compiler to prefetch data into closer levels of cache. Prefetching data can minimize the effects of memory latency. NOPREFETCH disables data prefetching. These directives give fine-level control to the programmer to influence the prefetches generated by the compiler.

!DIR$ PREFETCH [var1[: hint1[: distance1]] [,var2[: hint2[: distance2]]]...]

!DIR$ PREFETCH *: hint[: distance]

!DIR$ NOPREFETCH [var1[,var2]...]

var

Is an optional memory reference.

hint

Is an optional integer initialization expression with the integer value 0, 1, 2, or 3. These are the same as the defined values FOR_K_PREFETCH_T0, FOR_K_PREFETCH_T1, FOR_K_PREFETCH_T2, or FOR_K_PREFETCH_NTA for hint in the intrinsic subroutine MM_PREFETCH. To use this argument, you must also specify var.

distance

Is an optional integer initialization expression with a value greater than 0. It indicates the number of (possibly vectorized) loop iterations ahead of which a prefetch is issued, before the corresponding load or store instruction. To use this argument, you must also specify var and hint.

To use these directives, compiler option [q or Q]opt-prefetch must be set. Note that this option is turned on by default if the compiler general optimization level is O2 or higher.

This directive affects the DO loop it precedes.

If you specify PREFETCH *, the hint and optional distance are used to prefetch all array accesses in the DO loop.

If you specify NOPREFETCH with no arguments, the following occurs:

If a loop includes expression A(j), placing !DIR$ PREFETCH A:0:d in front of the loop instructs the compiler to insert a vprefetch0 instruction for A within the loop that is d iterations ahead.

The PREFETCH directive takes precedence over the [q or Q]opt-prefetch-distance options.

The variables in a NOPREFETCH or PREFETCH directive take precedence over PREFETCH *.

A NOPREFETCH directive with no arguments negates all other PREFETCH directives for the following DO loop.

Example

! Issue no prefetches for A1
! Issue vector prefetch from L2 and higher caches for B with a distance
!   of 16 vectorized iterations ahead
! Issue vector prefetch from L1 and higher caches for B with a distance
!   of 4 vectorized iterations ahead
!DIR$ NOPREFETCH A1 
!DIR$ PREFETCH B:1:16
!DIR$ PREFETCH B:0:4
   DO J = 1,N
      A1(J) = B(J-1) + B(J+1)
   END DO

In the following example, array A will be prefetched with hint 0 and distance 5, arrays B and C will be prefetched with hint 1 and distance 10, and array D will not be prefetched:

!DIR$ PREFETCH *:1:10
!DIR$ PREFETCH A:0:5
!DIR$ NOPREFETCH D
    DO J = 1, N
       A (J) = B (J) + C (J) + D (J)
    END DO

See Also