| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(MappedScalar2D), | intent(inout) | :: | this |
subroutine Free_MappedScalar2D(this)
implicit none
class(MappedScalar2D),intent(inout) :: this
! Local
integer :: n,iError
logical :: mpiIsFinalized
! Host storage is owned by the pools in the parent type (Stage 6b), so the parent Free
! releases it rather than deallocating these pointers.
call Free_Scalar2D_t(this)
call gpuCheck(hipFree(this%interior_gpu))
call gpuCheck(hipFree(this%boundary_gpu))
call gpuCheck(hipFree(this%extBoundary_gpu))
call gpuCheck(hipFree(this%avgBoundary_gpu))
! boundarynormal_gpu is allocated in Init alongside the four above and must be released
! here with them. Omitting it leaks (N+1)*4*nElem*2*nvar reals on every Free/Init cycle,
! which the adaptive loop performs once per epoch for each of the model's five
! MappedScalar2D fields. Compare Free_Scalar2D in src/gpu/SELF_Scalar_2D.f90 and
! Free_Scalar3D in src/gpu/SELF_Scalar_3D.f90, which both free it.
call gpuCheck(hipFree(this%boundarynormal_gpu))
call gpuCheck(hipFree(this%jas_gpu))
if(c_associated(this%mortarBuff_gpu)) then
call gpuCheck(hipFree(this%mortarBuff_gpu))
this%mortarBuff_gpu = c_null_ptr
endif
if(c_associated(this%halo_sendbuf_gpu)) call gpuCheck(hipFree(this%halo_sendbuf_gpu))
if(c_associated(this%halo_recvbuf_gpu)) call gpuCheck(hipFree(this%halo_recvbuf_gpu))
this%halo_sendbuf_gpu = c_null_ptr
this%halo_recvbuf_gpu = c_null_ptr
if(allocated(this%halo_reqs)) then
! Persistent requests can only be released while MPI is still
! initialized; if the mesh (and its MPI finalization) was freed first,
! MPI has reclaimed them already.
call MPI_FINALIZED(mpiIsFinalized,iError)
if(.not. mpiIsFinalized) then
do n = 1,size(this%halo_reqs)
call MPI_REQUEST_FREE(this%halo_reqs(n),iError)
enddo
endif
deallocate(this%halo_reqs)
endif
this%halo_nactive = 0
this%halo_inflight = 0
this%halo_static_done = .false.
endsubroutine Free_MappedScalar2D