34
H. Murai et al.
Fig. 25 Example of reduction computation (1)
Fig. 26 Example of reduction computation (2)
If the above loops are parallelized just by adding a loop directive, the value of
the variable sum varies from node to node because it is calculated separately on
each node (Fig. 25). The value should be reduced to produce the right result.
XcalableMP C
#pragma xmp loop on t[i]
for(int i=0;i<10;i++){
a[i] = i+1;
sum += a[i];
5
}
XcalableMP Fortran
!$xmp loop on t(i)
do i=1, 10
a(i) = i
sum = sum + a(i)
5
enddo
Then, to correct the error in the above code, add a reduction clause to the
loop directive as follows (Fig. 26).
XcalableMP C
#include
#pragma xmp nodes p[2]
#pragma xmp template t[10]
#pragma xmp distribute t[block] onto p
H. Murai et al.
Fig. 25 Example of reduction computation (1)
Fig. 26 Example of reduction computation (2)
If the above loops are parallelized just by adding a loop directive, the value of
the variable sum varies from node to node because it is calculated separately on
each node (Fig. 25). The value should be reduced to produce the right result.
XcalableMP C
#pragma xmp loop on t[i]
for(int i=0;i<10;i++){
a[i] = i+1;
sum += a[i];
5
}
XcalableMP Fortran
!$xmp loop on t(i)
do i=1, 10
a(i) = i
sum = sum + a(i)
5
enddo
Then, to correct the error in the above code, add a reduction clause to the
loop directive as follows (Fig. 26).
XcalableMP C
#include
#pragma xmp nodes p[2]
#pragma xmp template t[10]
#pragma xmp distribute t[block] onto p
