Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

UNROLL_AND_JAM and NOUNROLL_AND_JAM

General Compiler Directive: Hints to the compiler to enable or disable loop unrolling and jamming. These directives can only be applied to iterative DO loops.

!DIR$ UNROLL_AND_JAM [(n)] -or- !DIR$ UNROLL_AND_JAM [=n]

!DIR$ NOUNROLL_AND_JAM

n

Is an integer constant. The range of n is 0 through 255.

The UNROLL_AND_JAM directive partially unrolls one or more loops higher in the nest than the innermost loop and fuses (jams) the resulting loops back together. This transformation allows more reuses in the loop.

This directive is not effective on innermost loops. You must ensure that the immediately following loop is not the innermost loop after compiler-initiated interchanges are completed.

Specifying this directive is a hint to the compiler that the unroll and jam sequence is legal and profitable. The compiler will enable this transformation whenever possible.

The UNROLL_AND_JAM directive must precede the DO statement for each DO loop it affects. If n is specified, the optimizer unrolls the loop n times. If n is omitted or if it is outside the allowed range, the optimizer chooses the number of times to unroll the loop. The compiler generates correct code by comparing n and the loop count.

This directive is supported only when compiler option O3 is set. The UNROLL_AND_JAM directive overrides any setting of loop unrolling from the command line.

When unrolling a loop increases register pressure and code size, it may be necessary to prevent unrolling of a nested or imperfect nested loop. In such cases, use the NOUNROLL_AND_JAM directive, which hints to the compiler not to unroll a specified loop.

Example

integer a(10,10), b(10,10), c(10,10), d(10,10)
integer i, j, k

!dir$ unroll_and_jam = 6

do i=1,10
  !dir$ unroll_and_jam (6)
  do j=1,10
    do k=1,10
      a (j, i) = a (j, i) + b (k, i) *c (k, j)
    end do              ! k
  end do                ! j
end do                  ! i

end