XcalableMP Programming Model and Language
35
5
int main(){
int a[10], sum = 0;
#pragma xmp align a[i] with t[i]
10 #pragma xmp loop on t[i] reduction(+:sum)
for(int i=0;i<10;i++){
a[i] = i+1;
sum += a[i];
}
15
printf("%d\n", sum);
return 0;
}
XcalableMP Fortran
program main
!$xmp nodes p(2)
!$xmp template t(10)
!$xmp distribute t(block) onto p
5
integer :: a(10), sum = 0
!$xmp align a(i) with t(i)
!$xmp loop on t(i) reduction(+:sum)
do i=1, 10
10
a(i) = i
sum = sum + a(i)
enddo
write( * , * ) sum
15
end program main
An operator and target variables for reduction computation are specified in a
reduction clause. In the above examples, a “+” operator and a target variable
sum are specified for the reduction computation to produce a total sum among
nodes.
Operations that can be specified as an operator in a reduction clause are
limited to the following associative ones.
C
+
*
-
&
5 |
Précédent

- 43/265

Suivant