Handles the memory errors (including soft limit) during memory allocation
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | string |
Human-readable description string of the allocation operation, just for output purpose. |
||
integer(kind=ip), | intent(in) | :: | lall |
Amount of allocated memory in bytes |
||
integer(kind=ip), | intent(in) | :: | istat |
Status flag from allocate() |
subroutine chk_alloc(string, lall, istat)
!! Handles the memory errors (including soft limit)
!! during memory allocation
implicit none
integer(ip), intent(in) :: lall
!! Amount of allocated memory in bytes
integer(ip), intent(in) :: istat
!! Status flag from allocate()
character(len=*), intent(in) :: string
!! Human-readable description string of the allocation
!! operation, just for output purpose.
character(len=OMMP_STR_CHAR_MAX) :: msg
!! Message string for errors
real(rp) :: lall_gb
!! memory allocated in gb
lall_gb = lall / 1e9
if(istat /= 0) then
write(msg, "('Allocation error in subroutine ', a ,'. stat= ', i5)") string, istat
call fatal_error(msg)
else if(do_chk_limit .and. usedmem+lall_gb > maxmem) then
write(msg, "('Allocation error in subroutine ', a ,'. Not enough memory (internal limit ', i8, ' W).')") string, maxmem
call fatal_error(msg)
else
usedmem = usedmem + lall_gb
end if
if(usedmem > max_used) max_used = usedmem
end subroutine chk_alloc