30
H. Murai et al.
XcalableMP Fortran
!$xmp nodes p(4)
!$xmp tasks
!$xmp task on p(1:2)
5
call func_a()
!$xmp end task
!$xmp task on p(3:4)
call func_b()
!$xmp end task
10 !$xmp end tasks
Because the node sets specified by the on clauses of the task constructs
surrounded by a tasks construct are disjoint, they can be executed in parallel.
3.2 loop Construct
The loop construct is used to parallelize a loop.
XcalableMP C
#pragma xmp loop on t[i]
for (int i = 0; i < 10; i++)
a[i] = i;
XcalableMP Fortran
!$xmp loop on t(i)
do i = 1, 10
a(i) = i
end do
The loop directive above specifies that the iteration i of the following loop is
executed by the node that owns the template element t[i] or t(i), which is
specified in the on clause.
Such a loop must satisfy the following two conditions:
1. There is no data/control dependence among the iterations. In other words, the
iterations of the loop can be executed in any order to produce the same result.
2. Elements of distributed arrays, if any, are accessed only by the node(s) that
own(s) the elements.
The programs below are examples of a right loop directive and a loop statement.
Condition 1 is satisfied because i is the only one index of the distributed array a
that is accessed within the loop, and condition 2 is also satisfied because the indices
of the template in the on clause of the loop directive are identical to that of the
distributed array (Fig. 22).
Précédent

- 38/265

Suivant