Debian Codegraph @

libgomp/testsuite/libgomp.fortran/declare-target-link.f90

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