UNROLL - UNROLL - 57222

AOCC User Guide

Document_ID
57222
Release_Date
2026-05-12
Revision
5.2 English

This directive instructs the compiler about the number of times the loop should be unrolled.

!DIR$ UNROLL [(n)]

  • n – optional parameter; integer constant ranges from 1 - 512
  • When n equals 0, the compiler will decide if unrolling should happen or not.

To use this directive, compiler optimization level should be -O1 or above.

If n is specified, the optimizer unrolls the loop n times.

If n is not specified or out of range, the optimizer unrolls the loop based on profitability.

Example 1

subroutine func1(a, b)
 integer :: m = 10
 integer :: i, a(m), b(m)

 !dir$ unroll
 do i = 1, m
   b(i) = a(i) + 1
 end do
end subroutine func1

Example 2

subroutine func2(m, a, b)
 integer :: i, m, a(m), b(m)

 !dir$ unroll(4)
 do i = 1, m
   b(i) = a(i) + 1
 end do
end subroutine func2