Debian Codegraph @

libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-1.f90

raw
1 ! { dg-do run }
2 ! Test whether use_device_ptr properly handles OPTIONAL arguments
3 ! (Only case of present arguments is tested)
4 program test_it
5 implicit none
6 integer, target :: ixx
7 integer, pointer :: ptr_i, ptr_null
8
9 ptr_i => ixx
10 call foo(ptr_i)
11
12 ptr_null => null()
13 call bar(ptr_null)
14
15 call foo_absent()
16 call bar_absent()
17 contains
18 subroutine foo(ii)
19 integer, pointer, optional :: ii
20
21 if (.not.present(ii)) stop 1
22 if (.not.associated(ii, ixx)) stop 2
23 !$omp target data map(to:ixx) use_device_ptr(ii)
24 if (.not.present(ii)) stop 3
25 if (.not.associated(ii)) stop 4
26 !$omp end target data
27 end subroutine foo
28
29 ! For bar, it is assumed that a NULL ptr on the host maps to NULL on the device
30 subroutine bar(jj)
31 integer, pointer, optional :: jj
32
33 if (.not.present(jj)) stop 5
34 if (associated(jj)) stop 6
35 !$omp target data map(to:ixx) use_device_ptr(jj)
36 if (.not.present(jj)) stop 7
37 if (associated(jj)) stop 8
38 !$omp end target data
39 end subroutine bar
40
41 subroutine foo_absent(ii)
42 integer, pointer, optional :: ii
43
44 if (present(ii)) STOP 31
45 !$omp target data map(to:ixx) use_device_ptr(ii)
46 if (present(ii)) STOP 32
47 !$omp end target data
48 end subroutine foo_absent
49
50 ! For bar, it is assumed that a NULL ptr on the host maps to NULL on the device
51 subroutine bar_absent(jj)
52 integer, pointer, optional :: jj
53
54 if (present(jj)) STOP 41
55 !$omp target data map(to:ixx) use_device_ptr(jj)
56 if (present(jj)) STOP 42
57 !$omp end target data
58 end subroutine bar_absent
59 end program test_it