aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/target-firstprivate-2.f90
blob: d00b4070c11abc811de13c81236bbd6e52236bb5 (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
! PR fortran/104949

module m
use omp_lib
implicit none (type, external)

contains
subroutine one
  integer, allocatable :: x(:)
  integer :: i

  do i = 1, omp_get_num_devices() + 1
    !$omp target firstprivate(x)
      if (allocated(x)) error stop
    !$omp end target
    if (allocated(x)) error stop
  end do

  do i = 1, omp_get_num_devices() + 1
    !$omp target firstprivate(x, i)
      if (allocated(x)) error stop
      x = [10,20,30,40] + i
      if (any (x /= [10,20,30,40] + i)) error stop
      ! This leaks memory!
      ! deallocate(x)
    !$omp end target
    if (allocated(x)) error stop
  end do

  x = [1,2,3,4]

  do i = 1, omp_get_num_devices() + 1
    !$omp target firstprivate(x, i)
      if (i <= 0) error stop
      if (.not.allocated(x)) error stop
      if (size(x) /= 4) error stop
      if (lbound(x,1) /= 1) error stop
      if (any (x /= [1,2,3,4])) error stop
      ! no reallocation, just malloced + assignment
      x = [10,20,30,40] + i
      if (any (x /= [10,20,30,40] + i)) error stop
      ! This leaks memory!
      ! deallocate(x)
    !$omp end target
    if (.not.allocated(x)) error stop
    if (size(x) /= 4) error stop
    if (lbound(x,1) /= 1) error stop
    if (any (x /= [1,2,3,4])) error stop
  end do
  deallocate(x)
end

subroutine two
  character(len=:), allocatable :: x(:)
  character(len=5)  :: str
  integer :: i

  str = "abcde" ! work around for PR fortran/91544
  do i = 1, omp_get_num_devices() + 1
    !$omp target firstprivate(x)
      if (allocated(x)) error stop
    !$omp end target
    if (allocated(x)) error stop
  end do

  do i = 1, omp_get_num_devices() + 1
    !$omp target firstprivate(x, i)
      if (allocated(x)) error stop
      ! no reallocation, just malloced + assignment
      x = [character(len=2+i) :: str,"fhji","klmno"]
      if (len(x) /= 2+i) error stop
      if (any (x /= [character(len=2+i) :: str,"fhji","klmno"])) error stop
      ! This leaks memory!
      ! deallocate(x)
    !$omp end target
    if (allocated(x)) error stop
  end do

  x = [character(len=4) :: "ABCDE","FHJI","KLMNO"]

  do i = 1, omp_get_num_devices() + 1
    !$omp target firstprivate(x, i)
      if (i <= 0) error stop
      if (.not.allocated(x)) error stop
      if (size(x) /= 3) error stop
      if (lbound(x,1) /= 1) error stop
      if (len(x) /= 4) error stop
      if (any (x /= [character(len=4) :: "ABCDE","FHJI","KLMNO"])) error stop
      !! Reallocation runs into the issue PR fortran/105538
      !!
      !!x = [character(len=2+i) :: str,"fhji","klmno"]
      !!if (len(x) /= 2+i) error stop
      !!if (any (x /= [character(len=2+i) :: str,"fhji","klmno"])) error stop
      !! This leaks memory!
      !! deallocate(x)
      ! Just assign:
      x = [character(len=4) :: "abcde","fhji","klmno"]
      if (any (x /= [character(len=4) :: "abcde","fhji","klmno"])) error stop
    !$omp end target
    if (.not.allocated(x)) error stop
    if (lbound(x,1) /= 1) error stop
    if (size(x) /= 3) error stop
    if (len(x) /= 4) error stop
    if (any (x /= [character(len=4) :: "ABCDE","FHJI","KLMNO"])) error stop
  end do
  deallocate(x)
end
end module m

use m
call one
call two
end