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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
! { dg-additional-options "-Wall" }
! PR fortran/115559
! PR middle-end/115637
module m
integer :: A
!$omp declare target link(A)
end module m
subroutine f
implicit none (type, external)
integer, save :: x, y ! { dg-warning "Unused variable 'y' declared" }
!$omp declare target link(x, y)
! note: y is not 'link' as gfortran doesn't regard it as used
x = 6
call ii
contains
subroutine k
!$omp declare target
use m
A = 5
end
subroutine ii
integer :: res
!$omp target map(x) map(from: res)
call k()
call ll()
res = get()
!$omp end target
! print *, res
if (res /= 6 + 7 + 5) &
stop 1
end
subroutine ll
!$omp declare target
x = x + 7
end
integer function get()
use m
!$omp declare target
get = x + A
end
end
subroutine sub
implicit none (type, external)
integer, save :: arr(100), arr2(1:4)
!$omp declare target link(arr,arr2)
call mapit
call device1
call re_mapit
call device2
contains
subroutine mapit
integer :: i
arr = [(i, i=1,100)]
!$omp target enter data map(to:arr(10:50)) map(alloc: arr2(1:4))
end subroutine
subroutine re_mapit
integer :: i
!$omp target exit data map(from:arr(10:50)) map(delete: arr2)
if (any (arr(1:9) /= [(i, i=1,9)])) stop 2
if (any (arr(10:50) /= [(3-10*i, i=10,50)])) stop 3
if (any (arr(51:100) /= [(i, i=51,100)])) stop 4
end subroutine
subroutine device1
integer :: res
!$omp target map(from:res)
res = run_device1()
!$omp end target
! print *, res
if (res /= -11436) stop 5
end
integer function run_device1()
!$omp declare target
integer :: i
run_device1 = -99
arr2 = [11,22,33,44]
if (any (arr(10:50) /= [(i, i=10,50)])) then
run_device1 = arr(11)
return
end if
run_device1 = sum(arr(10:13) + arr2)
do i = 10, 50
arr(i) = 3 - 10 * arr(i)
end do
run_device1 = run_device1 + sum(arr(15:50))
end
subroutine device2
end
integer function run_device2()
!$omp declare target
run_device2 = -99
end
end
use m
implicit none (type, external)
external f
external sub
!$omp target enter data map(alloc: A)
call f()
call sub
end
|