Debian Codegraph @

libgomp/testsuite/libgomp.fortran/target-has-device-addr-3.f90

raw
1 ! Test optional dummy arguments in HAS_DEVICE_ADDR.
2
3 program main
4 use omp_lib
5 use iso_c_binding
6 implicit none
7
8 integer, target :: x
9 integer, pointer :: ptr
10 integer, parameter :: N=7
11 real :: y1(N), y2(N)
12 integer, target :: y3(N:2*N-1)
13 integer :: i
14
15 x = 24
16 ptr => x
17 y1 = 42.24
18 y2 = 42.24
19 y3 = 42
20
21 call optional_scalar (is_present=.false.)
22 if (x /= 24) stop 1
23
24 call optional_scalar (x, is_present=.true.)
25 if (x /= 42) stop 2
26
27 call optional_ptr (is_present=.false.)
28 if (x /= 42) stop 3
29 if (ptr /= 42) stop 4
30
31 call optional_ptr (ptr, is_present=.true.)
32 if (x /= 84) stop 5
33 if (ptr /= 84) stop 6
34
35 call optional_array (is_present=.false.)
36 if (any (y1 /= [(42.24, i=1, N)])) stop 7
37 if (any (y2 /= [(42.24, i=1, N)])) stop 8
38 if (any (y3 /= [(42, i=1, N)])) stop 9
39
40 call optional_array (y1, y2, y3, is_present=.true.)
41 if (any (y1 /= [(42.24+i, i=1, N)])) stop 10
42 if (any (y2 /= [(42.24+2*i, i=1, N)])) stop 11
43 if (any (y3 /= [(42+3*i, i=1, N)])) stop 12
44
45 contains
46 subroutine optional_scalar (a, is_present)
47 integer, optional :: a
48 logical, value :: is_present
49
50 !$omp target data map(a) use_device_addr(a)
51 !$omp target has_device_addr(a)
52 if (is_present) a = 42
53 !$omp end target
54 !$omp end target data
55 end subroutine optional_scalar
56
57 subroutine optional_ptr (a, is_present)
58 integer, pointer, optional :: a
59 logical, value :: is_present
60 !$omp target data map(a) use_device_addr(a)
61 !$omp target has_device_addr(a)
62 if (is_present) a = 84
63 !$omp end target
64 !$omp end target data
65 end subroutine optional_ptr
66
67 subroutine optional_array (a, b, c, is_present)
68 real, optional :: a(:), b(*)
69 integer, optional, pointer, intent(in) :: c(:)
70 logical, value :: is_present
71 integer :: i
72
73 !$omp target data map(a, b(:N), c) use_device_addr(a, b, c)
74 !$omp target has_device_addr(a, b, c)
75 if (is_present) then
76 if (lbound(a,dim=1) /= 1 .or. ubound(a,dim=1) /= N) stop 21
77 if (lbound(b,dim=1) /= 1) stop 22
78 if (lbound(c,dim=1) /= N .or. ubound(c,dim=1) /= 2*N-1) stop 23
79 if (any (a /= [(42.24, i = 1, N)])) stop 24
80 if (any (b(:N) /= [(42.24, i = 1, N)])) stop 25
81 if (any (c /= [(42, i = 1, N)])) stop 26
82 a = [(42.24+i, i=1, N)]
83 b(:N) = [(42.24+2*i, i=1, N)]
84 c = [(42+3*i, i=1, N)]
85 end if
86 !$omp end target
87 !$omp end target data
88 end subroutine optional_array
89
90 end program main