1

I have a large Fortran code in which I have edited the main routine to run multiple times in a loop.

I see the program memory growing as the loop runs, and am trying to track down where the memory is being leaked. (I have used massif, but it didn't help)

I am now attempting to monitor the memory use with reads of the /proc/'pid'/status file and examining vmRSS and vmSIZE.

My question is, as the loop runs multiple times the memory used grows at different points within the loop - despite the fact that the loop does the same thing each time.

So is there a delay in the reporting of memory use in the status file, and if so how would I go about tracking down where the memory is being allocated in this way.

abinitio
  • 609
  • 6
  • 20
  • 1
    Have you tried [valgrind](https://www.valgrind.org/)? – jack Feb 10 '21 at 13:28
  • See related https://stackoverflow.com/questions/6261201/how-to-find-memory-leak-in-a-c-code-project?noredirect=1&lq=1 Just translate C++ `new` and `delete` to Fortran `allocate` and `deallocate`. – Vladimir F Героям слава Feb 10 '21 at 13:33
  • Your compiler might have some diagnostics. Gfortran has address sanitizations `-fsanitize=address`. Look for pointers that are being allocated and not deallocated. – Vladimir F Героям слава Feb 10 '21 at 13:34
  • Thanks for the suggestions. I've tried valgrind, using massif - it doesn't produce anything helpful. Finding and deallocating everywhere is what I need to do, but the code is quite sprawling - so I was hoping to use examining the vmRSS at various stages through the run in order to drill down and see where allocation is being done. Unfortunately it doesnt seem to be consistent. – abinitio Feb 11 '21 at 09:06

1 Answers1

0

Note that vmRSS is not solely due to what your program is doing, it's affected by other things going on in your system as well. If there is memory pressure, the OS may decide to swap out less used memory pages, unmap mapped pages, etc., thus reducing the RSS.

Also, when your code allocates memory e.g. with the ALLOCATE statement, RSS doesn't increase, just the vmSIZE. RSS only comes into play when you actually start writing to the allocated memory.

janneb
  • 36,249
  • 2
  • 81
  • 97