If I do a deallocation of an array inside a subroutine inside a fortran openmp offload kernel I get a crash.
This works fine:
program prototype
implicit none
integer :: i, k
integer :: num_elems
integer, allocatable, dimension(:) :: testb
num_elems = 1800
!$omp target loop
do i=1,num_elems
allocate(testb(1:5))
do k= 1,5
testb(k) = k
end do
deallocate(testb)
end do
!$omp end target loop
end program prototype
But this crashes:
module some_module
implicit none
contains
subroutine test_allocs(i)
!$omp declare target
implicit none
integer, intent(in) :: i
integer :: k
real, allocatable, dimension(:) :: testb
allocate(testb(1:5))
do k= 1,5
testb(k) = k
end do
deallocate(testb)
end subroutine
end module some_module
program prototype
use some_module
implicit none
integer :: i
integer :: num_elems
num_elems = 1800
!$omp target loop
do i=1,num_elems
call test_allocs(i)
end do
!$omp end target loop
end program prototype
If I remove the deallocate it doesn’t crash. Should I never deallocate explicitly and simply rely on implicit deallocation as the variable goes out of scope?