aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/target-has-device-addr-4.f90
blob: 59d3e3d31dd110fc26684edd21f9045be2f8dbe8 (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
! Test allocatables in HAS_DEVICE_ADDR.

program main
  use omp_lib
  use iso_c_binding
  implicit none

  integer, parameter :: N = 5
  integer, allocatable :: x
  integer, allocatable :: y(:)
  call scalar_dummy (x)
  call array_dummy (y)
  call array_dummy_optional (y)
  call array_dummy_optional ()

contains
  subroutine scalar_dummy (a)
    integer, allocatable :: a

    allocate (a)
    a = 24

    !$omp target data map(a) use_device_addr(a)
      !$omp target has_device_addr(a)
        a = 42
      !$omp end target
    !$omp end target data
    if (a /= 42) stop 1

    deallocate (a)
  end subroutine scalar_dummy

  subroutine array_dummy (a)
    integer, allocatable :: a(:)
    integer :: i

    allocate (a(N))
    a = 42

    !$omp target data map(a) use_device_addr(a)
      !$omp target has_device_addr(a)
        a = [(i, i=1, N)]
      !$omp end target
    !$omp end target data
    if (any (a /= [(i, i=1, N)])) stop 2

    deallocate (a)
  end subroutine array_dummy

  subroutine array_dummy_optional (a)
    integer, optional, allocatable :: a(:)
    integer :: i

    if (present (a)) then
      allocate (a(N))
      a = 42
    end if

    !$omp target data map(a) use_device_addr(a)
      !$omp target has_device_addr(a)
        if (present (a)) a = [(i, i=1, N)]
      !$omp end target
    !$omp end target data

    if (present (a)) then
      if (any (a /= [(i, i=1, N)])) stop 2
      deallocate (a)
    end if
  end subroutine array_dummy_optional

end program main