| 1 |
module m |
| 2 |
use omp_lib |
| 3 |
implicit none |
| 4 |
!!$omp requires dynamic_allocators |
| 5 |
|
| 6 |
integer :: final_count |
| 7 |
|
| 8 |
type t |
| 9 |
integer :: i = 0 |
| 10 |
integer, allocatable :: A(:,:) |
| 11 |
contains |
| 12 |
final :: count_finalization |
| 13 |
end type t |
| 14 |
|
| 15 |
contains |
| 16 |
|
| 17 |
elemental impure subroutine count_finalization(self) |
| 18 |
type(t), intent(in) :: self |
| 19 |
final_count = final_count + 1 |
| 20 |
end |
| 21 |
|
| 22 |
subroutine test(allocator) |
| 23 |
integer(omp_allocator_handle_kind), optional, value :: allocator |
| 24 |
call zero_size(allocator) |
| 25 |
call finalization_test(allocator) |
| 26 |
end subroutine test |
| 27 |
|
| 28 |
subroutine finalization_test(allocator) |
| 29 |
integer(omp_allocator_handle_kind), optional, value :: allocator |
| 30 |
integer :: n = 5 |
| 31 |
|
| 32 |
final_count = 0; |
| 33 |
block |
| 34 |
type(t) :: A |
| 35 |
! !$omp allocate(A) allocator(allocator) |
| 36 |
A%i = 1 |
| 37 |
end block |
| 38 |
if (final_count /= 1) & |
| 39 |
stop 10 |
| 40 |
|
| 41 |
final_count = 0; |
| 42 |
block |
| 43 |
type(t) :: B(7) |
| 44 |
!$omp allocate(B) allocator(allocator) |
| 45 |
B(1)%i = 1 |
| 46 |
end block |
| 47 |
if (final_count /= 7) stop 10 |
| 48 |
|
| 49 |
final_count = 0; |
| 50 |
block |
| 51 |
type(t) :: C(n) |
| 52 |
! !$omp allocate(C) allocator(allocator) |
| 53 |
C(1)%i = 1 |
| 54 |
end block |
| 55 |
if (final_count /= 5) stop 10 |
| 56 |
|
| 57 |
final_count = 0; |
| 58 |
block |
| 59 |
type(t) :: D(0) |
| 60 |
! !$omp allocate(D) allocator(allocator) |
| 61 |
D(1:0)%i = 1 |
| 62 |
end block |
| 63 |
if (final_count /= 0) stop 10 |
| 64 |
end subroutine |
| 65 |
|
| 66 |
subroutine zero_size(allocator) |
| 67 |
integer(omp_allocator_handle_kind), optional, value :: allocator |
| 68 |
integer :: n |
| 69 |
n = -3 |
| 70 |
|
| 71 |
block |
| 72 |
integer :: A(n) |
| 73 |
character(len=n) :: B |
| 74 |
! !$omp allocate(A,b) allocator(allocator) |
| 75 |
if (size(A) /= 0 .or. len(b) /= 0) & |
| 76 |
stop 1 |
| 77 |
B(1:len(b)) ='A' |
| 78 |
end block |
| 79 |
|
| 80 |
!!$omp target |
| 81 |
block |
| 82 |
integer :: A(n) |
| 83 |
character(len=n) :: B |
| 84 |
! !$omp allocate(A,b) allocator(allocator) |
| 85 |
if (size(A) /= 0 .or. len(b) /= 0) & |
| 86 |
stop 2 |
| 87 |
B(1:len(b)) ='A' |
| 88 |
end block |
| 89 |
end |
| 90 |
end module |
| 91 |
|
| 92 |
use m |
| 93 |
call test() |
| 94 |
call test(omp_default_mem_alloc) |
| 95 |
call test(omp_large_cap_mem_alloc) |
| 96 |
call test(omp_high_bw_mem_alloc) |
| 97 |
call test(omp_low_lat_mem_alloc) |
| 98 |
call test(omp_cgroup_mem_alloc) |
| 99 |
end |