Loop Count and Loop Distribution

Loop Count

The loop count pragma indicates the loop count is likely to be an integer constant. The syntax for this pragma is shown below:

Syntax

#pragma loop count (n)

where n is an integer value.

The value of loop count affects heuristics used in software pipelining and data prefetch.

Example: Using loop count

void loop_count(int a[], int b[])

{

  #pragma loop count (10000)

  for (int i=0; i<1000; i++)

// This should enable

// software pipelinging for this loop.

    a[i] = b[i] + 1.2;

}

Loop Distribution

The distribute point pragma indicates a preference for performing loop distribution. The syntax for this pragma is shown below:

Syntax

#pragma distribute point

Loop distribution may cause large loops be distributed into smaller ones. This strategy might enable more loops to get software-pipelined.

Example: 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;

  }

}