Allocate CPU variable with memory checking (kind I8P, rank 2).
use penf
integer(I8P), allocatable :: a(:,:)
integer(I4P) :: ulb(2,2)=reshape([1,1, &
1,2],&
[2,2])
call allocate_variable(a, ulb)
print*, allocated(a)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=I8P), | intent(inout), | allocatable | :: | var(:,:) |
Varibale to be allocate on CPU. |
|
integer(kind=I4P), | intent(in) | :: | ulb(2,2) |
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_I8P_2D(var, ulb, msg, verbose) !< Allocate CPU variable with memory checking (kind I8P, rank 2). !< !<```fortran !< use penf !< integer(I8P), allocatable :: a(:,:) !< integer(I4P) :: ulb(2,2)=reshape([1,1, & !< 1,2],& !< [2,2]) !< call allocate_variable(a, ulb) !< print*, allocated(a) !<``` !=> T <<< integer(I8P), allocatable, intent(inout) :: var(:,:) !< Varibale to be allocate on CPU. integer(I4P), intent(in) :: ulb(2,2) !< 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))) 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_I8P_2D