forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coarrays_02.f90
28 lines (27 loc) · 1.08 KB
/
coarrays_02.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
program coarrays_02
! Source https://j3-fortran.org/doc/year/18/18-007r1.pdf Page no - 541
use, intrinsic :: iso_fortran_env
integer, allocatable :: node (:) ! tree nodes that this image handles.
integer, allocatable :: nc (:)
! node(i) has nc(i) children.
integer, allocatable :: parent (:), sub (:)
! the parent of node (i) is node (sub (i)) [parent (i)].
type (event_type), allocatable :: done (:) [:]
integer :: i, j, status
! set up the tree, including allocation of all arrays.
do i = 1, size (node)
! wait for children to complete
if (nc (i) > 0) then
event wait (done (i), until_count=nc (i), stat=status)
if (status/=0) exit
end if
! process node, using data from children.
if (parent (i)>0) then
! node is not the root.
! place result on image parent (i) for node node (sub) [parent (i)]
! tell parent (i) that this has been done.
event post (done (sub (i)) [parent (i)], stat=status)
if (status/=0) exit
end if
end do
end program