1program subarrays
2  integer, parameter     :: n = 20, c = 10
3  integer                :: i, a(n), b(n)
4
5  a(:) = 0
6  b(:) = 0
7
8  ! COPY
9
10  !$acc parallel copy (a(1:n))
11  !$acc loop
12  do i = 1, n
13     a(i) = i
14  end do
15  !$acc end parallel
16
17  do i = 1, n
18     b(i) = i
19  end do
20
21  call check (a, b, n)
22
23  ! COPYOUT
24
25  a(:) = 0
26
27  !$acc parallel copyout (a(1:n))
28  !$acc loop
29  do i = 1, n
30     a(i) = i
31  end do
32  !$acc end parallel
33
34  do i = 1, n
35     if (a(i) .ne. b(i)) STOP 1
36  end do
37  call check (a, b, n)
38
39  ! COPYIN
40
41  a(:) = 0
42
43  !$acc parallel copyout (a(1:n)) copyin (b(1:n))
44  !$acc loop
45  do i = 1, n
46     a(i) = i
47  end do
48  !$acc end parallel
49
50  call check (a, b, n)
51
52  ! PRESENT_OR_COPY
53
54  !$acc parallel pcopy (a(1:n))
55  !$acc loop
56  do i = 1, n
57     a(i) = i
58  end do
59  !$acc end parallel
60
61  call check (a, b, n)
62
63  ! PRESENT_OR_COPYOUT
64
65  a(:) = 0
66
67  !$acc parallel pcopyout (a(1:n))
68  !$acc loop
69  do i = 1, n
70     a(i) = i
71  end do
72  !$acc end parallel
73
74  call check (a, b, n)
75
76  ! PRESENT_OR_COPYIN
77
78  a(:) = 0
79
80  !$acc parallel pcopyout (a(1:n)) pcopyin (b(1:n))
81  !$acc loop
82  do i = 1, n
83     a(i) = i
84  end do
85  !$acc end parallel
86
87  call check (a, b, n)
88end program subarrays
89
90subroutine check (a, b, n)
91  integer :: n, a(n), b(n)
92  integer :: i
93
94  do i = 1, n
95     if (a(i) .ne. b(i)) STOP 2
96  end do
97end subroutine check
98