Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(memory_print_option): fix summary output #1466

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions src/Utilities/Memory/MemoryHelper.f90
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,16 @@ subroutine split_mem_path(mem_path, component, subcomponent)
character(len=*), intent(in) :: mem_path !< path to the memory object
character(len=LENCOMPONENTNAME), intent(out) :: component !< name of the component (solution, model, exchange)
character(len=LENCOMPONENTNAME), intent(out) :: subcomponent !< name of the subcomponent (package)

! local
character(len=LENMEMPATH) :: local_mem_path
integer(I4B) :: idx

idx = index(mem_path, memPathSeparator, back=.true.)
call strip_context_mem_path(mem_path, local_mem_path)

idx = index(local_mem_path, memPathSeparator, back=.true.)
! if the separator is found at the end of the string,
! the path is invalid:
if (idx == len(mem_path)) then
if (idx == len_trim(local_mem_path)) then
write (errmsg, '(*(G0))') &
'Fatal error in Memory Manager, cannot split invalid memory path: ', &
mem_path
Expand All @@ -119,21 +121,39 @@ subroutine split_mem_path(mem_path, component, subcomponent)

if (idx > 0) then
! when found:
component = mem_path(:idx - 1)
subcomponent = mem_path(idx + 1:)
component = local_mem_path(:idx - 1)
subcomponent = local_mem_path(idx + 1:)
else
! when not found, there apparently is no subcomponent:
component = mem_path
component = local_mem_path(:LENCOMPONENTNAME)
subcomponent = ''
end if

! remove context specifier if prepended to component
idx = index(component, memPathSeparator, back=.true.)
if (idx > 0 .and. component(1:2) == '__') then
component = component(idx + 1:)
end subroutine split_mem_path

!> @brief Remove the context from the memory path
!!
!! NB: when there is no context in the memory path, the
!! original memory path is returned.
!<
subroutine strip_context_mem_path(mem_path, mem_path_no_context)
character(len=*), intent(in) :: mem_path !< path to the memory object
character(len=LENMEMPATH), intent(inout) :: mem_path_no_context !< path to the memory object without the context
! local
integer(I4B) :: idx

! initialize the local mem_path
mem_path_no_context = mem_path

if (mem_path(1:2) == '__') then
idx = index(mem_path, memPathSeparator)
if (idx > 0) then
mem_path_no_context = ' '
mem_path_no_context = mem_path(idx + 1:)
end if
end if

end subroutine split_mem_path
end subroutine strip_context_mem_path

!> @brief Generic routine to check the length of (parts of) the memory address
!!
Expand Down
7 changes: 5 additions & 2 deletions src/Utilities/Memory/MemoryManager.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module MemoryManagerModule
use SimModule, only: store_error, count_errors
use MemoryTypeModule, only: MemoryType
use MemoryListModule, only: MemoryListType
use MemoryHelperModule, only: mem_check_length, split_mem_path
use MemoryHelperModule, only: mem_check_length, split_mem_path, &
strip_context_mem_path
use TableModule, only: TableType, table_cr
use CharacterStringModule, only: CharacterStringType

Expand Down Expand Up @@ -2829,6 +2830,7 @@ subroutine mem_write_usage(iout)
! -- local
class(MemoryType), pointer :: mt
character(len=LENMEMPATH), allocatable, dimension(:) :: cunique
character(len=LENMEMPATH) :: mem_path
character(LEN=10) :: cunits
integer(I4B) :: ipos
integer(I4B) :: icomp
Expand Down Expand Up @@ -2872,7 +2874,8 @@ subroutine mem_write_usage(iout)
ilen = len_trim(cunique(icomp))
do ipos = 1, memorylist%count()
mt => memorylist%Get(ipos)
if (cunique(icomp) /= mt%path(1:ilen)) cycle
call strip_context_mem_path(mt%path, mem_path)
if (cunique(icomp) /= mem_path(1:ilen)) cycle
if (.not. mt%master) cycle
if (mt%memtype(1:6) == 'STRING') then
nchars = nchars + mt%isize * mt%element_size
Expand Down