interchange

Date:

01-09-2012

NAME

interchange, interchange - specify whether or not the order of the following two or more loops should be interchanged

SYNOPSIS

#pragma _CRI interchange(loop_number1, loop_number2[, loop_number3] ...)
#pragma _CRI nointerchange
loop_number

Specifies two or more loop_number names. The loop_number names can be specified in any order, and the compiler reorders the loops. The loops must be perfectly nested. If the loops are not perfectly nested, you may receive unexpected results.

!DIR$ INTERCHANGE (do_variable1,do_variable2 [,do_variable3]...)
!DIR$ NOINTERCHANGE
do_variable

Specifies two or more do_variable names. The do_variable names can be specified in any order, and the compiler reorders the loops. The loops must be perfectly nested. If the loops are not perfectly nested, you may receive unexpected results.

IMPLEMENTATION

Cray Linux Environment (CLE)

DESCRIPTION

Scope: Local

The loop interchange control directives specify whether or not the order of the following two or more loops should be interchanged. These directives apply to the loops immediately following directive.

The syntax for C/C++ programs differs slightly from Fortran syntax.

In C/C++, the loops affected by the interchange directive are designated by their position within the loop nest. Loop numbers range from 1, the outermost loop, to the nesting depth of the most deeply nested loop. They can be specified in any order, and the compiler reorders the loops according their number. The loops must be perfectly nested, or you may receive unexpected results. The compiler reorders the loops such that the loop with loop-number1 is outermost, then loop-number2, followed by loop-number3. The nointerchange directive inhibits loop interchange on the loop that immediately follows the directive.

In Fortran, the loops affected by the INTERCHANGE directive are designated by their variable names. The compiler reorders the loops such that the loop with do_variable1 is outermost, then loop do_variable2, then loop do_variable3. The NOINTERCHANGE directive inhibits loop interchange on the loop that immediately follows the directive.

EXAMPLES

Example 1: interchange directive

In the following example in C/C++, the interchange directive reorders the loops; the k loop becomes the outermost, followed by j, and the i loop the innermost:

#define N 100

A[N][N][N];

void
f(int n)
{
  int i, j, k;

#pragma _CRI interchange( 2, 3, 1 )
  for (i=0; i < n; i++) {
    for (k=0; k < n; k++) {
      for (j = 0; j < n; j++) {
        A[k][j][i] = 1.0;
      }
    }
  }
}

Example 2: INTERCHANGE directive

In the following example in Fortran, the interchange directive reorders the loops; the K loop becomes the outermost, followed by J, and the I loop the innermost:

!DIR$ INTERCHANGE (K, J, I)
                     DO I = 1,NSIZE1
                             DO K = 1,NSIZE1
                                     DO J = 1,NSIZE1
                                             X(I,J) = X(I,J) + Y(I,K) * Z(K,J)
                                     ENDDO
                             ENDDO
                     ENDDO

SEE ALSO

intro_directives(7)