aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/get-mapped-ptr-2.f90
blob: 66a0b88f612fecf70a24f7ec46247606c6d1e42a (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
program main
  use omp_lib
  use iso_c_binding
  implicit none (external, type)
  integer :: d, id, i, j
  integer, target :: a, b(1:2), c(1:2), e(0:127)
  type(c_ptr) :: p1, p2, p3, q, devptrs(0:63)

  a = 42;
  q = c_loc (a);
  e = [(i, i = 0, 127)]

  d = omp_get_default_device ()
  id = omp_get_initial_device ()

  if (d < 0 .or. d >= omp_get_num_devices ()) &
    d = id

  if (d /= id) then
    !$omp target data map(alloc: a, b, c(2), e(32:95)) device(d)
      !$omp target map(from: p1, p2, p3, devptrs) map(alloc: a, b, c(2), e(32:95)) device(d)
      p1 = c_loc (a);
      p2 = c_loc (b);
      p3 = c_loc (c(2))
      devptrs = [(c_loc (e(i)), i = 32, 95)]
      !$omp end target

      if (.not. c_associated (omp_get_mapped_ptr (c_loc (a), d), p1) &
          .or. .not. c_associated (omp_get_mapped_ptr (q, d), p1) &
          .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b), d), p2) &
          .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b(1)), d), p2) &
          .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(2)), d), p3) &
          .or. c_associated (omp_get_mapped_ptr (c_loc (c(1)), d))) &
        stop 0

      do j = 0, 31
        if (c_associated (omp_get_mapped_ptr (c_loc (e(j)), d))) &
          stop 1
      end do
      do j = 32, 95
        if (.not. c_associated (omp_get_mapped_ptr (c_loc (e(j)), d), devptrs(j-32))) &
          stop 2
      end do
      do j = 96, 128
        if (c_associated (omp_get_mapped_ptr (c_loc (e(j)), d))) &
          stop 3
      end do
    !$omp end target data

    if (c_associated (omp_get_mapped_ptr (c_loc (a), d)) &
        .or. c_associated (omp_get_mapped_ptr (q, d)) &
        .or. c_associated (omp_get_mapped_ptr (c_loc (b), d)) &
        .or. c_associated (omp_get_mapped_ptr (c_loc (b(1)), d)) &
        .or. c_associated (omp_get_mapped_ptr (c_loc (c(2)), d)) &
        .or. c_associated (omp_get_mapped_ptr (c_loc (c(1)), d))) &
      stop 4
      do j = 0, 127
        if (c_associated (omp_get_mapped_ptr (c_loc (e(j)), d))) &
          stop 5
      end do

    !$omp target enter data map (alloc: a, b, c(2), e(32:95)) device (d)
      !$omp target map(from: p1, p2, p3, devptrs) map(alloc: a, b, c(2), e(32:95)) device(d)
      p1 = c_loc (a);
      p2 = c_loc (b);
      p3 = c_loc (c(2))
      devptrs = [(c_loc (e(i)), i = 32, 95)]
      !$omp end target

      if (.not. c_associated (omp_get_mapped_ptr (c_loc (a), d), p1) &
          .or. .not. c_associated (omp_get_mapped_ptr (q, d), p1) &
          .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b), d), p2) &
          .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(2)), d), p3) &
          .or. c_associated (omp_get_mapped_ptr (c_loc (c(1)), d))) &
        stop 6

      do j = 0, 31
        if (c_associated (omp_get_mapped_ptr (c_loc (e(j)), d))) &
          stop 7
      end do
      do j = 32, 95
        if (.not. c_associated (omp_get_mapped_ptr (c_loc (e(j)), d), devptrs(j-32))) &
          stop 8
      end do
      do j = 96, 128
        if (c_associated (omp_get_mapped_ptr (c_loc (e(j)), d))) &
          stop 9
      end do
    !$omp target exit data map (delete: a, b, c(2), e(32:95)) device (d)

    if (c_associated (omp_get_mapped_ptr (c_loc (a), d)) &
        .or. c_associated (omp_get_mapped_ptr (q, d)) &
        .or. c_associated (omp_get_mapped_ptr (c_loc (b), d)) &
        .or. c_associated (omp_get_mapped_ptr (c_loc (b(1)), d)) &
        .or. c_associated (omp_get_mapped_ptr (c_loc (c(1)), d)) &
        .or. c_associated (omp_get_mapped_ptr (c_loc (c(2)), d))) &
      stop 10
    do j = 0, 127
      if (c_associated (omp_get_mapped_ptr (c_loc (e(j)), d))) &
        stop 11
    end do

  else ! d == id

    !$omp target data map(alloc: a, b, c(2), e(32:95)) device(d)
      !$omp target map(from: p1, p2, p3, devptrs) map(alloc: a, b, c(2), e(32:95)) device(d)
      p1 = c_loc (a);
      p2 = c_loc (b);
      p3 = c_loc (c(2))
      devptrs = [(c_loc (e(i)), i = 32, 95)]
      !$omp end target

      if (.not. c_associated (omp_get_mapped_ptr (c_loc (a), d), c_loc (a)) &
        .or. .not. c_associated (omp_get_mapped_ptr (q, d), q) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b), d), c_loc (b)) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b(1)), d), c_loc (b(1))) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(2)), d), c_loc (c(2))) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(1)), d), c_loc (c(1)))) &
      stop 12

      do j = 0, 127
        if (.not. c_associated (omp_get_mapped_ptr (c_loc (e(j)), d), c_loc (e(j)))) &
          stop 13
      end do
    !$omp end target data

    if (.not. c_associated (omp_get_mapped_ptr (c_loc (a), d), c_loc (a)) &
        .or. .not. c_associated (omp_get_mapped_ptr (q, d), q) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b), d), c_loc (b)) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b(1)), d), c_loc (b(1))) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(2)), d), c_loc (c(2))) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(1)), d), c_loc (c(1)))) &
      stop 14
    do j = 0, 127
      if (.not. c_associated (omp_get_mapped_ptr (c_loc (e(j)), d))) &
        stop 15
    end do

    !$omp target enter data map (alloc: a, b, c(2), e(32:95)) device (d)
      !$omp target map(from: p1, p2, p3, devptrs) map(alloc: a, b, c(2), e(32:95)) device(d)
      p1 = c_loc (a);
      p2 = c_loc (b);
      p3 = c_loc (c(2))
      devptrs = [(c_loc (e(i)), i = 32, 95)]
      !$omp end target

      if (.not. c_associated (omp_get_mapped_ptr (c_loc (a), d), c_loc (a)) &
        .or. .not. c_associated (omp_get_mapped_ptr (q, d), q) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b), d), c_loc (b)) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b(1)), d), c_loc (b(1))) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(2)), d), c_loc (c(2))) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(1)), d), c_loc (c(1)))) &
        stop 16

      do j = 0, 127
        if (.not. c_associated (omp_get_mapped_ptr (c_loc (e(j)), d), c_loc (e(j)))) &
          stop 17
      end do
    !$omp target exit data map (delete: a, b, c(2), e(32:95)) device (d)

    if (.not. c_associated (omp_get_mapped_ptr (c_loc (a), d), c_loc (a)) &
        .or. .not. c_associated (omp_get_mapped_ptr (q, d), q) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b), d), c_loc (b)) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (b(1)), d), c_loc (b(1))) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(2)), d), c_loc (c(2))) &
        .or. .not. c_associated (omp_get_mapped_ptr (c_loc (c(1)), d), c_loc (c(1)))) &
      stop 18

    do j = 0, 127
      if (.not. c_associated (omp_get_mapped_ptr (c_loc (e(j)), d), c_loc (e(j)))) &
        stop 19
    end do
  end if

end program main