Skip to content

Introduce ModEM getrusage module to record high-water memory mark#44

Open
MiCurry wants to merge 1 commit intomagnetotellurics:mainfrom
MiCurry:modem-getrusage
Open

Introduce ModEM getrusage module to record high-water memory mark#44
MiCurry wants to merge 1 commit intomagnetotellurics:mainfrom
MiCurry:modem-getrusage

Conversation

@MiCurry
Copy link
Copy Markdown
Member

@MiCurry MiCurry commented Mar 12, 2026

Currently, the ModEM_memory module is not used anywhere in ModEM.

This pull requests adds two new files to ModEM, ModEM_memory.f90 and ModEM_getrusage.c. ModEM_getrusage.c is a C file that calls the getrusage system call (see man 2 getrusage) and returns ru_maxrss, the maximum resident set size, or a max used memory high-water mark in bytes.

ModEM_memory.f90 contains routines to either log or print ru_maxrss. The report conveniently prints the maxrss in bytes, KB, MB and GB and along with a developer specified message.

It also contains a subroutine for the main task to calculate the total maxrss across tasks by using MPI_reduce. Of course, all tasks have to coordinate and call this routine at the same time. Only the main task writes out the result.

Because this commit contains C code, I have coded it in a way that it can only be compiled by CMake and if -DMODEM_MEMORY=on is specified in the CMake build command.

If this module is used in ModEM, and the user builds with the ./configure build system, ModEM_memory_get_maxrss will throw an error telling the user that the C code is not compiled and how to compile it. If we use this module in ModEM we might want to include calls to it to be wraped around #ifdef MODEM_MEMORY preprocessing statements.

I have been using this module to record high water mark when developing the ESolnManager project, it has been quite useful and @akelbert has suggest it be included in.

Currently, the ModEM_memory module is not used anywhere in ModEM.

This commit adds two new files to ModEM, ModEM_memory.f90 and
ModEM_getrusage.c. ModEM_getrusage.c is a C file that calls the getrusage
system call (see `man 2 getrusage`) and returns `ru_maxrss`, the maximum
resident set size, or a max used memory high-water mark.

ModEM_memory.f90 contains routines to either log or print `ru_maxrss`, when it
does so it conveniently prints the maxrss in bytes, KB, MB and GB and allows
the developer to specify a unique message with the output.

It also contains a subroutine for the main task to calculate the total maxrss
across tasks by using MPI_reduce. Of course, all tasks have to coordinate and
call this routine at the same time. Only the main task writes out the result.

Because this commit contains C code, I have coded it in a way that it can only
be compiled by CMake and if `-DMODEM_MEMORY=on` is specified in the CMake build
command.

If this module is used in ModEM, and the user builds with the `./configure`
build system, `ModEM_memory_get_maxrss` will throw an error telling the user
that the C code is not compiled and how to compile it.
conversion = 1000.0;
#else
conversion = 1.0;
#endif
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to double check this conversion is right...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant