Ada: Memory measurement tools

Introduction

The memory which is limited on Ada is the virtual memory. It is limited via the parameter as_limit in the submission script. The virtual memory is equivalent to the quantity of memory reserved for each process. With the following tools, you can know the maximum consumption of virtual memory of your codes: the idrmemmpi module, used for an MPI program; the idrmem module, used for an OpenMP or sequential program; and the subroutine procstat which can be inserted in your code.

Module idrmemmpi

The library idrmemmpi allows displaying the maximum consumption of virtual memory by an MPI program during its execution. The display is shown at the moment the execution stops. It is necessary to load this module before the compilation of your program:

  
$ module load idrmemmpi
$ mpiifort main.f90 -o main 

It is not necessary to make any changes in the submission script. At the end of the execution, you will obtain the following information on the standard output: elapsed time, maximum consumption of virtual memory (VMSizeMax), maximum consumption of physical memory (RSSMax), maximum consumption of the stack (StackMax) and, in addition, the process ranks on which these maximums were 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 wish to display the current consumption at a precise moment, you simply insert a call to the routine idr_print_mem:

  CALL idr_print_mem()

Known problems with the idrmemmpi module:

  • In MPMD mode, all of the codes must be compiled with idrmemmpi.

Module idrmem

We supply the tool idrmem, available with the module command, for use with a sequential code or OpenMP. With this tool, the maximum consumption in virtual memory is displayed at the moment when the program stops.

$ module load idrmem
$ idrmem ./executable

You can also use idrmem for MPI codes although idrmemmpi is preferred.

''module load idrmem''
''poe idrmem ./executable''

You will obtain the elapsed time, maximum consumption of physcial memory and maximum stack consumption in the standard output:

  IdrisMem v1.1 : elapsed = 24.61 s, VMSizeMax = 1257 MB, RSSMax = 791 MB, StackMax = 92 kB

Known problems with the idrmem module:

  • Does not stop immediately when there is a call to MPI_ABORT: Use idrmemmpi instead.
  • Does not work with an alias command.
  • Does not give good results if the command is a script (or an executable file) which launches other executable files.
  • There will not be a display if the wall clock limit is reached during the execution time.

Subroutine procstat

If you have added the following Fortran subroutine to your code, you may obtain at any given moment during the program execution a display of the maximum memory consumption up until that moment:

subroutine_procstat
subroutine procstat()
  character(len=128) :: key, word1, word2
  integer :: iter
  ! Opening of the file
  OPEN ( UNIT   = 42 ,          FILE     = '/proc/self/status', &
         FORM   = 'formatted' , ACCESS   = 'sequential',        &
         ACTION = 'read' ,      POSITION = 'rewind' )
 
  ! Read the executable file name (for verification).
  READ (UNIT =42 , FMT=* ) key, word1
  ! Pass over the 10 lines which follow.
  READ (UNIT=42, FMT='(9/)')
  ! Recuperate Vmpeak
  READ (UNIT =42 , FMT=* ) key, word1, word2
  print *, 'procstat : VMSizeMax = ', trim(word1), trim(word2)
  ! Pass over the 2 lines wich follow.
  READ (UNIT=42, FMT='(1/)')
  READ (UNIT =42 , FMT=* ) key, word1,word2
  print *, 'procstat : RSSMax = ', trim(word1), trim(word2)
  READ (UNIT=42, FMT='(/)')
  READ (UNIT =42 , FMT=* ) key, mot1, mot2
  print *, 'procstat : StackMax = ', trim(word1), trim(word2)
  CLOSE ( UNIT =42 )
end subroutine procstat

Subsequently, if you insert a call procstat() in your code at any moment, you will have a display in the standard output of the maximum consumption of virtual memory, physical memory and the stack from the beginning of the launch of the application up to the moment when you inserted the call.