25module mpp_memutils_mod
28 use mpp_mod,
only:
mpp_error, fatal, stderr, mpp_npes
38 logical :: memuse_started = .false.
45 if(memuse_started)
then
46 call mpp_error(fatal,
"mpp_memutils_mod: mpp_memuse_begin was already called")
48 memuse_started = .true.
57 character(len=*),
intent(in) :: text
58 integer,
intent(in),
optional :: unit
60 real :: m, mmin, mmax, mavg, mstd, end_memuse
63 if(.NOT.memuse_started)
then
64 call mpp_error(fatal,
"mpp_memutils_mod: mpp_memuse_begin must be called before calling mpp_memuse_being")
66 memuse_started = .false.
70 mu = stderr();
if(
PRESENT(unit) )mu = unit
71 m = end_memuse - begin_memuse
74 mavg = m;
call mpp_sum(mavg); mavg = mavg/mpp_npes()
75 mstd = (m-mavg)**2;
call mpp_sum(mstd); mstd = sqrt( mstd/mpp_npes() )
76 if( mpp_pe().EQ.mpp_root_pe() )
write( mu,
'(a64,4es11.3)' ) &
77 'Memory(MB) used in '//trim(text)//
'=', mmin, mmax, mstd, mavg
86 character(len=*),
intent(in) :: text
87 integer,
intent(in),
optional :: unit
89 real :: m, mmin, mmax, mavg, mstd
92 mu = stderr();
if(
PRESENT(unit) )mu = unit
97 mavg = m;
call mpp_sum(mavg); mavg = mavg/mpp_npes()
98 mstd = (m-mavg)**2;
call mpp_sum(mstd); mstd = sqrt( mstd/mpp_npes() )
99 if( mpp_pe().EQ.mpp_root_pe() )
write( mu,
'(a64,4es11.3)' ) &
100 'Memuse(MB) at '//trim(text)//
'=', mmin, mmax, mstd, mavg
111 real,
intent(out) :: memuse
114 integer(KIND=c_size_t) function getpeakrss()
bind(c, name="getpeakrss")
115 use,
intrinsic :: iso_c_binding
116 end function getpeakrss
120 real,
parameter :: b_to_mib = 1048576.0
123 memuse = real(getpeakrss())/b_to_mib
127end module mpp_memutils_mod
subroutine, public mpp_mem_dump(memuse)
Return the memory high water mark in MiB.
subroutine, public mpp_print_memuse_stats(text, unit)
Print the current memory high water mark to stderr, or the unit specified.
subroutine, public mpp_memuse_begin
Initialize the memory module, and record the initial memory use.
subroutine, public mpp_memuse_end(text, unit)
End the memory collection, and report on total memory used during the execution of the model run.
Reduction operations. Find the max of scalar a from the PEs in pelist result is also automatically br...
Reduction operations. Find the min of scalar a from the PEs in pelist result is also automatically br...