The LOOP COUNT directive can affect heuristics used in vectorization, loop-transformations, and software pipelining (IA-64 architecture). The directive can specific the minimum, maximum, or average number of iterations for a DO loop. In addition, a list of commonly occurring values can be specified. This behavior might help the compiler generate multiple versions and perform complete unrolling.
The syntax for this directive supports the following syntax variations:
Syntax |
---|
!DEC$ LOOP COUNT (n) !DEC$ LOOP COUNT = n or !DEC$ LOOP COUNT (n1[,n2]...) !DEC$ LOOP COUNT = n1[,n2]... or !DEC$ LOOP COUNT MAX(n), MIN(n), AVG(n) !DEC$ LOOP COUNT MAX=n, MIN=n, AVG=n |
The syntax variations support the following arguments:
Argument |
Description |
---|---|
(n) or =n |
Non-negative integer value. The compiler will attempt to iterate the next loop the number of times specified in n; however, the number of iterations is not guaranteed. |
(n1[,n2]...) or = n1[,n2]... |
Non-negative integer values. The compiler will attempt to iterate the next loop the number of time specified by n1 or n2, or some other unspecified number of times. This behavior allows the compiler some flexibility in attempting to unroll the loop. The number of iterations is not guaranteed. |
min(n), max(n), avg(n) or min=n, max=n, avg=n |
Non-negative integer values. Specify one or more in any order without duplication. The compiler insures the next loop iterates for the specified maximum, minimum, or average number (n1) of times. The specified number of iterations is guaranteed for min and max. |
You can specify more than one directive for a single loop; however, do not duplicate the directive
The following example illustrates how to use the directive to iterate through the loop and enable software pipelining on IA-64 architectures.
Using Loop Count (n) |
---|
subroutine loop_count(a, b, N) integer :: i, N, b(N), c(N) !DEC$ LOOP COUNT (1000) do i = 1, 1000 b(i) = a(i) + 1 enddo end subroutine loop_count |
The following example illustrates how to use the directive to iterate through the loop a minimum of three, a maximum of ten, and average of five times.
Using Loop Count min, max, avg |
---|
!DEC$ LOOP COUNT MIN(3), MAX(10), AVG(5) DO i = 1, 15 PRINT i END DO |
The DISTRIBUTE POINTdirectiveinstructs the compiler to prefer loop distribution at the location indicated. The syntax for this directive is shown below:
Syntax |
---|
!DEC$ DISTRIBUTE POINT |
Loop distribution can cause large loops to be distributed into smaller ones. This strategy can enable software pipelining for the new, smaller loops (IA-64 architecture).
If the directive is placed inside a loop, distribution is performed after the directive and any loop-carried dependency is ignored.
If the directive is placed before a loop, the compiler determines where to distribute the loops and observes data dependency. If they are placed inside the loop, the compiler supports multiple instances of the directive.
Using distribute point |
---|
subroutine dist1(a, b, c, d, N) integer :: i, N, a(N), b(N), c(N), d(N) !DEC$ DISTRIBUTE POINT do i = 1, N b(i) = a(i) + 1 c(i) = a(i) + b(i) ! Compiler will decide where to distribute. ! Data dependency is observed. d(i) = c(i) + 1 enddo end subroutine dist1
subroutine dist2(a, b, c, d, N) integer :: i, N, a(N), b(N), c(N), d(N) do i = 1, N b(i) = a(i) + 1 !DEC$ DISTRIBUTE POINT ! Distribution will start here, ignoring all ! loop-carried dependency. c(i) = a(i) + b(i) d(i) = c(i) + 1 enddo end subroutine dist2 |
See General Compiler Directives for more information about these directives.