Loop Unrolling Support

The UNROLL[n] directive tells the compiler how many times to unroll a counted loop.

The general syntax for this directive is shown below:

Syntax

!DEC$ UNROLL(n)

where n  is an integer constant from 0 through 255.

The UNROLL  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 assigns the number of times to unroll the loop.

This directive is supported only when option -O3 (Linux*) or /O3 (Windows*) is used. The UNROLL directive overrides any setting of loop unrolling from the command line.

Currently, the directive can be applied only for the innermost loop nest. If applied to the outer loop nests, it is ignored. The compiler generates correct code by comparing n and the loop count.

Example

subroutine unroll(a, b, c, d)

  integer :: i, b(100), c(100), d(100)

  !DEC$ UNROLL(4)

  do i = 1, 100

    b(i) = a(i) + 1

    d(i) = c(i) + 1

  enddo

end subroutine unroll

For more details on these directives, see "Directive Enhanced Compilation", section "General Directives", in the Intel® Fortran Language Reference.