Skip to content

Commit

Permalink
Merge pull request #2509 from GEOS-ESM/feature/bmauer/mem_report_utility
Browse files Browse the repository at this point in the history
Add generic memory profiling utility
  • Loading branch information
tclune authored Dec 22, 2023
2 parents d5b695e + 3a8deba commit e3a1fdb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added memory utility, MAPL_MemReport that can be used in any code linking MAPL

### Changed

- Updated ESMF required version to 8.6.0
Expand Down
29 changes: 29 additions & 0 deletions base/MAPL_MemUtils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module MAPL_MemUtilsMod
public MAPL_MemUtilsFree
public MAPL_MemCommited
public MAPL_MemUsed
public MAPL_MemReport

#ifdef _CRAY
public :: hplen
Expand Down Expand Up @@ -767,4 +768,32 @@ subroutine get_unit ( iunit )
return
end subroutine get_unit

subroutine MAPL_MemReport(comm,file_name,line,decorator,rc)
integer, intent(in) :: comm
character(len=*), intent(in) :: file_name
integer, intent(in) :: line
character(len=*), intent(in), optional :: decorator
integer, intent(out), optional :: rc

real :: mem_total,mem_used,percent_used
real :: committed_total,committed,percent_committed
integer :: rank,status
character(len=:), allocatable :: extra_message

#ifdef sysDarwin
RETURN_(ESMF_SUCCESS)
#endif
call MPI_Barrier(comm,status)
if (present(decorator)) then
extra_message = decorator
else
extra_message = ""
end if
call MAPL_MemUsed(mem_total,mem_used,percent_used)
call MAPL_MemCommited(committed_total,committed,percent_committed)
call MPI_Comm_Rank(comm,rank,status)
if (rank == 0) write(*,'("Mem report ",A20," ",A30," ",i7," ",f5.1,"% : ",f5.1,"% Mem Comm:Used")')trim(extra_message),file_name,line,percent_committed,percent_used

end subroutine

end module MAPL_MemUtilsMod

0 comments on commit e3a1fdb

Please sign in to comment.