This page was translated by an AI (LLM) with a cursory human check and is awaiting full review.
Measuring memory and the idrmem tools
Introduction
On Jean Zay, the memory limit applies to the physical memory actually used by your program.
Therefore, we provide you with the idrmem tools to determine the maximum physical memory consumption during the execution of your programs.
There are two idrmem tools: one for MPI codes (MPI library idrmem) and another for OpenMP or sequential codes (command idrmem). They return information about memory usage at the end of the program execution.
The various idrmem tools are available via the module command:
$ module avail idrmem
------- /gpfslocalsup/pub/modules-idris/modulefiles/linux-rhel7-x86_64 -------
idrmem/1.4 idrmem/1.4-mpi
Usage with MPI codes
In this case, it is the MPI library idrmem that displays the maximum consumption of virtual memory and physical memory used by an MPI code during its execution. Note that the display occurs when the program executes one of the instructions MPI_Finalize or MPI_Abort.
It is essential to load the corresponding module to compile your MPI program by linking it with the idrmem library:
$ module load idrmem/1.4-mpi
$ mpiifort main.f90 -o main -lidrmem
However, no changes are necessary in the submission script (no module to load, nor command to execute).
At the end of the execution, the standard output will display the elapsed time (elapsed), the maximum virtual memory consumption (VMSizeMax), the maximum physical memory consumption (RSSMax), and the maximum stack consumption (StackMax), as well as the ranks of the MPI processes where these maximums are reached:
IdrisMemMPI v1.4 : elapsed = 0.32 s, VMSizeMax = 497 mB on rank 1, RSSMax = 28 mB on rank 0, StackMax = 408 kB on rank 1
If you want to display the current consumption at a specific moment, simply insert a call to the routine idr_print_mem provided with the MPI library idrmem in your code:
CALL idr_print_mem()
Known issues with the MPI idrmem library
- In MPMD mode, it is necessary for all codes to be compiled with the MPI library
idrmem. - If, for any reason, the program does not execute either the
MPI_Finalizeinstruction or theMPI_Abortinstruction, no information will be returned.
Usage with OpenMP or sequential codes
In this case, it is the command idrmem that displays, at the moment the program stops, the maximum consumption of physical and virtual memory.
To use it with a sequential or OpenMP code, simply load the corresponding module and use the idrmem command to execute your program:
$ module load idrmem/1.4
$ idrmem ./executable_seq
Note that the idrmem command can also be used with MPI codes, although the MPI library idrmem is preferable. You should then do the following:
$ module load idrmem/1.4
$ srun idrmem ./executable_mpi
The idrmem command displays in the standard output the elapsed time, the maximum virtual memory consumption (VMSizeMax), the maximum physical memory consumption (RSSMax), and the maximum stack consumption (StackMax):
IdrisMem v1.4 : elapsed = 24.61 s, VMSizeMax = 1257 MB, RSSMax = 791 MB, StackMax = 92 kB
To perform measurements during execution, we propose the procstat procedure to insert into your code (see below).
Known issues with the idrmem command
- Does not work with a command that is an alias;
- Does not give correct results if the executable is a script or an executable that launches other executables;
- If the execution time limit (
#SBATCH --time=HH:MM:SS) is reached, there will be no display; - Does not stop immediately upon a call to
MPI_Abort, use the MPI libraryidrmemfor MPI codes instead.
Procstat procedure
If you want to be able to display the maximum memory consumption at any time, here is a Fortran procedure that you can add to your code:
subroutine procstat()
character(len=128) :: key, mot1, mot2
integer :: ios, iter, My_unit
! Ouverture du fichier
OPEN ( NEWUNIT = My_unit , FILE = '/proc/self/status', &
FORM = 'formatted' , ACCESS = 'sequential', &
ACTION = 'read' , POSITION = 'rewind' ,&
IOSTAT = ios )
IF ( ios /= 0 ) stop " Probleme a l'ouverture "
! Lecture du nom de l'executable (pour verification)
READ (UNIT =My_unit , FMT=*, IOSTAT = ios ) key, mot1
DO WHILE (trim(key) /= "VmPeak:")
READ (UNIT =My_unit , FMT=*, IOSTAT = ios ) key, mot1,mot2
END DO
print *, "procstat : VMSizeMax = ", trim(mot1), trim(mot2)
DO WHILE (trim(key) /= "VmHWM:")
READ (UNIT =My_unit , FMT=*, IOSTAT = ios ) key, mot1, mot2
END DO
print *, "procstat : RSSMax = ", trim(mot1), trim(mot2)
DO WHILE (trim(key) /= "VmStk:")
READ (UNIT =My_unit , FMT=*, IOSTAT = ios ) key, mot1, mot2
END DO
print *, "procstat : StackMax = ", trim(mot1), trim(mot2)
CLOSE ( UNIT =My_unit )
end subroutine procstat
Then a call procstat() in your code will cause the standard output to display the maximum consumption of virtual memory, physical memory, and stack since the program started.