EnsurePool Subroutine

public subroutine EnsurePool(pool, needed)

Guarantee that pool has at least needed elements, growing it by poolGrowth when it must reallocate. Existing contents are NOT preserved: every caller re-establishes the array contents after resizing (the solution through the AMR transfer, the geometry through GenerateFromMesh, everything else by being written before it is read), so copying the old data would be wasted bandwidth.

Arguments

TypeIntentOptionalAttributesName
real(kind=prec), intent(inout), pointer, contiguous:: pool(:)
integer, intent(in) :: needed

Called by

proc~~ensurepool~~CalledByGraph proc~ensurepool EnsurePool proc~maparrays_tensor2d_t MapArrays_Tensor2D_t proc~maparrays_tensor2d_t->proc~ensurepool proc~maparrays_vector2d_t MapArrays_Vector2D_t proc~maparrays_vector2d_t->proc~ensurepool proc~maparrays_scalar2d_t MapArrays_Scalar2D_t proc~maparrays_scalar2d_t->proc~ensurepool

Contents

Source Code


Source Code

  subroutine EnsurePool(pool,needed)
    !! Guarantee that pool has at least `needed` elements, growing it by poolGrowth when it must
    !! reallocate. Existing contents are NOT preserved: every caller re-establishes the array
    !! contents after resizing (the solution through the AMR transfer, the geometry through
    !! GenerateFromMesh, everything else by being written before it is read), so copying the old
    !! data would be wasted bandwidth.
    implicit none
    real(prec),pointer,contiguous,intent(inout) :: pool(:)
    integer,intent(in) :: needed
    ! Local
    integer :: capacity

    if(associated(pool)) then
      if(size(pool) >= needed) return
      deallocate(pool)
    endif

    capacity = max(needed,int(real(needed,prec)*poolGrowth))
    allocate(pool(1:capacity))

  endsubroutine EnsurePool