Resize_MappedScalar3D Subroutine

public subroutine Resize_MappedScalar3D(this, interp, nVar, nElem)

Rebind to a new element count, reusing host pools and device buffers where they fit (AMR Stage 6b), and without uploading zeros the way Init does.

The mortar buffers are sized by mesh%nMortars, not nElem, and nMortars changes with the mesh independently of the element count, so they are invalidated here and lazily re-created at the right size by the next mortar exchange. Leaving a stale buffer in place would silently under-size that exchange.

Arguments

TypeIntentOptionalAttributesName
class(MappedScalar3D), intent(inout) :: this
type(Lagrange), intent(in), target:: interp
integer, intent(in) :: nVar
integer, intent(in) :: nElem

Calls

proc~~resize_mappedscalar3d~~CallsGraph proc~resize_mappedscalar3d Resize_MappedScalar3D proc~resize_mappedscalar3d_t Resize_MappedScalar3D_t proc~resize_mappedscalar3d->proc~resize_mappedscalar3d_t proc~gpucheck gpuCheck proc~resize_mappedscalar3d->proc~gpucheck mpi_request_free mpi_request_free proc~resize_mappedscalar3d->mpi_request_free proc~ensuredevicebuffers_mappedscalar3d EnsureDeviceBuffers_MappedScalar3D proc~resize_mappedscalar3d->proc~ensuredevicebuffers_mappedscalar3d interface~hipfree hipFree proc~resize_mappedscalar3d->interface~hipfree proc~resize_scalar3d_t Resize_Scalar3D_t proc~resize_mappedscalar3d_t->proc~resize_scalar3d_t ensuredevicebuffers_scalar3d ensuredevicebuffers_scalar3d proc~ensuredevicebuffers_mappedscalar3d->ensuredevicebuffers_scalar3d ensuredevicebuffer ensuredevicebuffer proc~ensuredevicebuffers_mappedscalar3d->ensuredevicebuffer

Contents

Source Code


Source Code

  subroutine Resize_MappedScalar3D(this,interp,nVar,nElem)
    !! Rebind to a new element count, reusing host pools and device buffers where they fit
    !! (AMR Stage 6b), and without uploading zeros the way Init does.
    !!
    !! The mortar buffers are sized by mesh%nMortars, not nElem, and nMortars changes with the
    !! mesh independently of the element count, so they are invalidated here and lazily
    !! re-created at the right size by the next mortar exchange. Leaving a stale buffer in place
    !! would silently under-size that exchange.
    implicit none
    class(MappedScalar3D),intent(inout) :: this
    type(Lagrange),intent(in),target :: interp
    integer,intent(in) :: nVar
    integer,intent(in) :: nElem
    ! Local
    integer :: n,iError

    call Resize_MappedScalar3D_t(this,interp,nVar,nElem)
    call EnsureDeviceBuffers_MappedScalar3D(this)
    if(c_associated(this%mortarBuff_gpu)) then
      call gpuCheck(hipFree(this%mortarBuff_gpu))
      this%mortarBuff_gpu = c_null_ptr
    endif

    ! The aggregated halo-exchange state is sized by the mesh/partition, not by nElem
    ! alone: the packed buffer bytes scale with the shared-side count, the persistent
    ! requests bake in per-neighbor counts, displacements, and ranks, and
    ! halo_static_done records that the static (non-stepped) variables' traces have
    ! already been carried - none of which survives a regrid. Tear all of it down so
    ! the next SideExchangeStart rebuilds against the new mesh; leaving it in place
    ! made the first post-regrid pack kernel write a grown halo through the old,
    ! smaller buffer (a GPU memory fault on the multi-rank adaptive path).
    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
      ! Resize runs between time steps with MPI up (unlike Free, which may run after
      ! the last mesh finalized MPI), so the requests can be released unconditionally.
      do n = 1,size(this%halo_reqs)
        call MPI_REQUEST_FREE(this%halo_reqs(n),iError)
      enddo
      deallocate(this%halo_reqs)
    endif
    this%halo_nactive = 0
    this%halo_inflight = 0
    this%halo_static_done = .false.

  endsubroutine Resize_MappedScalar3D