Allocate CPU variable with memory checking (kind I1P, rank 2).
use penf
integer(I1P), allocatable :: a(:,:)
integer(I4P) :: ulb(2,2)=reshape([1,1, &
1,2],&
[2,2])
open(unit=666, file='doctest-mem.log')
call allocate_variable(a, ulb, file_unit=666, verbose=.true.)
close(666, status='delete')
print*, allocated(a)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=I1P), | intent(inout), | allocatable | :: | var(:,:) |
Varibale to be allocate on CPU. |
|
| integer(kind=I4P), | intent(in) | :: | ulb(2,2) |
Upper/lower bounds of variable. |
||
| integer(kind=I4P), | intent(in), | optional | :: | file_unit |
File unit for verbose output. |
|
| 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_I1P_2D(var, ulb, file_unit, msg, verbose) !< Allocate CPU variable with memory checking (kind I1P, rank 2). !< !<```fortran !< use penf !< integer(I1P), allocatable :: a(:,:) !< integer(I4P) :: ulb(2,2)=reshape([1,1, & !< 1,2],& !< [2,2]) !< open(unit=666, file='doctest-mem.log') !< call allocate_variable(a, ulb, file_unit=666, verbose=.true.) !< close(666, status='delete') !< print*, allocated(a) !<``` !=> T <<< integer(I1P), allocatable, intent(inout) :: var(:,:) !< Varibale to be allocate on CPU. integer(I4P), intent(in) :: ulb(2,2) !< Upper/lower bounds of variable. integer(I4P), intent(in), optional :: file_unit !< File unit for verbose output. character(*), intent(in), optional :: msg !< Message to be printed in verbose mode. logical, intent(in), optional :: verbose !< Flag to activate verbose mode. integer(I4P) :: file_unit_ !< File unit for verbose output, local var. character(:), allocatable :: msg_ !< Message to be printed in verbose mode, local var. logical :: verbose_ !< Flag to activate verbose mode, local var. integer(I8P) :: mem_free, mem_total !< CPU memory. file_unit_ = stdout ; if (present(file_unit)) file_unit_ = file_unit 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) write(file_unit_,'(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) write(file_unit_,'(A)') msg_//'free/total memory AFTER allocate:'//trim(str([mem_free,mem_total]))//'[bytes]' endif endsubroutine alloc_var_I1P_2D