00001
00002
00003
00004
00005
00006 MODULE shr_mem_mod
00007
00008 use shr_kind_mod, only : shr_kind_r8
00009 use shr_log_mod, only: s_logunit => shr_log_Unit
00010
00011 implicit none
00012 private
00013
00014
00015
00016 public :: shr_mem_getusage, &
00017 shr_mem_init
00018
00019
00020
00021 real(shr_kind_r8) :: mb_blk = 0.0_shr_kind_r8
00022
00023
00024 CONTAINS
00025
00026
00027 subroutine shr_mem_init(prt)
00028
00029 implicit none
00030
00031
00032
00033 logical, optional :: prt
00034
00035
00036
00037
00038 integer :: msize
00039 integer :: mrss
00040 integer :: msize0,msize1
00041 integer :: mrss0,mrss1,mrss2
00042 integer :: mshare,mtext,mdatastack
00043 logical :: lprt
00044 integer :: ierr
00045
00046 integer :: GPTLget_memusage
00047
00048 real(shr_kind_r8),allocatable :: mem_tmp(:)
00049
00050
00051
00052 lprt = .false.
00053 if (present(prt)) then
00054 lprt = prt
00055 endif
00056
00057 ierr = GPTLget_memusage (msize, mrss0, mshare, mtext, mdatastack)
00058 allocate(mem_tmp(1024*1024))
00059 mem_tmp = -1.0
00060 ierr = GPTLget_memusage (msize, mrss1, mshare, mtext, mdatastack)
00061 deallocate(mem_tmp)
00062 ierr = GPTLget_memusage (msize, mrss2, mshare, mtext, mdatastack)
00063 mb_blk = 0.0_shr_kind_r8
00064 if (mrss1 - mrss0 > 0) then
00065 mb_blk = (8.0_shr_kind_r8)/((mrss1-mrss0)*1.0_shr_kind_r8)
00066 endif
00067
00068 if (lprt) then
00069 write(s_logunit,'(A,f16.2)') '8 MB memory alloc in MB is ',(mrss1-mrss0)*mb_blk
00070 write(s_logunit,'(A,f16.2)') '8 MB memory dealloc in MB is ',(mrss1-mrss2)*mb_blk
00071 write(s_logunit,'(A,f16.2)') 'Memory block size conversion in bytes is ',mb_blk*1024_shr_kind_r8*1024.0_shr_kind_r8
00072 endif
00073
00074 end subroutine shr_mem_init
00075
00076
00077
00078 subroutine shr_mem_getusage(r_msize,r_mrss)
00079
00080 implicit none
00081
00082
00083 real(shr_kind_r8) :: r_msize,r_mrss
00084
00085
00086 integer :: msize,mrss
00087 integer :: mshare,mtext,mdatastack
00088 integer :: ierr
00089 integer :: GPTLget_memusage
00090
00091
00092
00093 ierr = GPTLget_memusage (msize, mrss, mshare, mtext, mdatastack)
00094 r_msize = msize*mb_blk
00095 r_mrss = mrss*mb_blk
00096
00097 end subroutine shr_mem_getusage
00098
00099
00100
00101 END MODULE shr_mem_mod