>> Japanese


Work Mapping

Loop directive

The loop construct specifies that each iteration of the following loop is executed by a node set specified by the on clause, so that the iterations are distributed among nodes and executed in parallel.

  • Specify the index to be divided between the loop and on statements. In the case of a single loop statement, this can be omitted.
  • on-ref specifies the template name or the node set name.
  • An operation of reduction clause is defined as follows.
  • [F] +, *, -, .and., .or., .eqv., .neqv., max, min, iand, ior, ieor, firstmax, firstmin, lastmax, lastmin
    [C] +, *, -, &, |, ^, &&, ||, max, min, firstmax, firstmin, lastmax, lastmin

Single loop

C
#pragma xmp loop on t[i]
for( i = 0; i < 20; i++){
   a[i] = func(i);
}
Fortran
!$xmp loop on t(i)
do i=1, 20
   a(i) = func(i)
end do

Nested loop

C
#pragma xmp loop (i,j) on t[i][j]
for( i = 0; i < 20; i++){
   for( j = 0; j < 10; j++){
      a[i][j] = func(i , j);
   }
}
Fortran
!$xmp loop (i,j) on t(i,j)
do j=1, 10
   do i=1, 20
      a(i, j) = func(i, j)
   end do
end do

Reduction clause

C
#pragma xmp loop on t[i] reduction(+:sum)
for( i = 0; i < 20; i++){
   sum += i;
}
Fortran
!$xmp loop on t(i) reduction(+:sum)
do i=1, 20
   sum = sum + i
end do

The following calculation is performed at each node (with four nodes).

C
nodecalculationsum
p[0]0+1+2+3+410
p[1]5+6+7+8+935
p[2]10+11+12+13+1460
p[3]15+16+17+18+1985
Fortran
nodecalculationsum
p(1)1+2+3+4+515
p(2)6+7+8+9+1040
p(3)11+12+13+14+1565
p(4)16+17+18+19+2090

After the end of the loop statement, the reduction clause causes a summation calculation to be performed based on the value of sums held at each node. In this case, a value of 190 in C, and a value of 210 in Fotran, is assigned to the sum in each node.