Allocate CPU variable with memory checking (kind R8P, rank 4).
use penf
real(R8P), allocatable :: a(:,:,:,:)
integer(I4P) :: ulb(2,4)=reshape([1,1, &
1,2, &
1,3, &
1,4],&
[2,4])
call allocate_variable(a, ulb)
print*, allocated(a)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=R8P), | intent(inout), | allocatable | :: | var(:,:,:,:) |
Varibale to be allocate on CPU. |
|
integer(kind=I4P), | intent(in) | :: | ulb(2,4) |
Upper/lower bounds of variable. |
||
character(len=*), | intent(in), | optional | :: | msg |
Message to be printed in verbose mode. |
|
logical, | intent(in), | optional | :: | verbose |
Flag to activate verbose mode. |
subroutine alloc_var_R8P_4D(var, ulb, msg, verbose) !< Allocate CPU variable with memory checking (kind R8P, rank 4). !< !<```fortran !< use penf !< real(R8P), allocatable :: a(:,:,:,:) !< integer(I4P) :: ulb(2,4)=reshape([1,1, & !< 1,2, & !< 1,3, & !< 1,4],& !< [2,4]) !< call allocate_variable(a, ulb) !< print*, allocated(a) !<``` !=> T <<< real(R8P), allocatable, intent(inout) :: var(:,:,:,:) !< Varibale to be allocate on CPU. integer(I4P), intent(in) :: ulb(2,4) !< Upper/lower bounds of variable. character(*), intent(in), optional :: msg !< Message to be printed in verbose mode. logical, intent(in), optional :: verbose !< Flag to activate verbose mode. character(:), allocatable :: msg_ !< Message to be printed in verbose mode, local var. logical :: verbose_ !< Flag to activate verbose mode, local var. integer(C_LONG) :: mem_free, mem_total !< CPU memory. msg_ = '' ; if (present(msg )) msg_ = msg verbose_ = .false. ; if (present(verbose)) verbose_ = verbose if (allocated(var)) deallocate(var) if (verbose_) then call get_memory_info(mem_total, mem_free) print '(A)', msg_//'free/total memory BEFORE allocate:'//trim(str([mem_free,mem_total]))//'[bytes]' endif allocate(var(ulb(1,1):ulb(2,1), ulb(1,2):ulb(2,2), ulb(1,3):ulb(2,3), ulb(1,4):ulb(2,4))) if (verbose_) then call get_memory_info(mem_total, mem_free) print '(A)', msg_//'free/total memory AFTER allocate:'//trim(str([mem_free,mem_total]))//'[bytes]' endif endsubroutine alloc_var_R8P_4D