The loop count pragma can affect heuristics used in vectorization, loop-transformations, and software pipelining (IA-64 architecture). The pragma can specific the minimum, maximum, or average number of iterations for a for 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 pragma supports the following syntax variations:
Syntax |
---|
#pragma loop count (n) #pragma loop count = n or #pragma loop count (n1[, n2]...) #pragma loop count = n1[, n2]... or #pragma loop count min(n), max(n), avg(n) #pragma loop count min=n, max=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 pragma for a single loop; however, do not duplicate the pragma.
The following example illustrates how to use the pragma to iterate through the loop and enable software pipelining on IA-64 architectures.
Using Loop Count (n) |
---|
void loop_count(int a[], int b[]) { #pragma loop count (10000) for (int i=0; i<1000; i++) a[i] = b[i] + 1.2; } |
The following example illustrates how to use the pragma to iterate through the loop a minimum of three, a maximum of ten, and average of five times.
Using Loop Count min, max, avg |
---|
#include <stdio.h> int i; int main() { #pragma loop count min(3), max(10), avg(5) for (i=1;i<=15;i++){ printf("i=%d\n",i); } |
The distribute point pragma instructs the compiler to prefer loop distribution at the location indicated. The syntax for this pragma is shown below:
Syntax |
---|
#pragma 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 pragma is placed inside a loop, distribution is performed after the directive and any loop-carried dependency is ignored.
If the pragma 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 pragma.
When the pragma is placed inside the loop, they cannot be put inside an if statement.
Using distribute point |
---|
void dist1(int a[], int b[], int c[], int d[]) { #pragma distribute point // Compiler will automatically decide where to // distribute. Data dependency is observed. for (int i=1; i<1000; i++) { b[i] = a[i] + 1; c[i] = a[i] + b[i]; d[i] = c[i] + 1; } }
void dist2(int a[], int b[], int c[], int d[]) { for (int i=1; i<1000; i++) { b[i] = a[i] + 1; #pragma distribute point // Distribution will start here, // ignoring all loop-carried dependency. c[i] = a[i] + b[i]; d[i] = c[i] + 1; } } |