4.6. Memory Tracking In Fortran

To profile memory usage in Fortran 90 use TAU's ability to selectively instrument a program. The option -optTauSelectFile=<file> for tau_compilier.sh let you specify a selective instrumentation file which defines regions of the source code to instrument.

To begin memory profiling, state which file/routines to profile by typing:


BEGIN_INSTRUMENT_SECTION
memory file="memory.f90" routine="INIT"
END_INSTRUMENT_SECTION

Wildcard can be used to instrument multiple routines. For file names * character can be used to specify any number of character, thus foo* matches foobar, foo2, etc. also for file names ? can match a single charater, ie. foo? matches foo2, fooZ, but not foobar. You can use # as a wildcard for routines, ie. b# matches bar, b2z etc.

Memory Profile in Fortran gives you these three metrics:

  • Total size of memory for each malloc and free in the source code.

  • The callpath for each occurrence of malloc or free.

  • A list of all variable that were not deallocated in the source code.

[Note] Note

Due to the limitations of the xlf compiler, The size of the memory reported for Fortran Array (compilied with xlf) is not the number of bytes but the number of elements.

Here is the profile for the example/memoryleakdetect/f90/foo.f90 file.

%> pprof
..
---------------------------------------------------------------------------------------
NumSamples   MaxValue   MinValue  MeanValue  Std. Dev.  Event Name
---------------------------------------------------------------------------------------
         1         16         16         16          0  MEMORY LEAK! malloc size <file=foo.f90, var=X, line=7> : MAIN => FOO => BAR 
         2         52         48         50          2  MEMORY LEAK! malloc size <file=foo.f90, var=X, line=7> : MAIN => FOO => G => BAR 
         1         80         80         80          0  free size <file=foo.f90, var=X, line=10>
         1         80         80         80          0  free size <file=foo.f90, var=X, line=10> : MAIN => FOO => G => BAR 
         1        180        180        180          0  free size <file=foo.f90, var=X, line=15>
         1        180        180        180          0  free size <file=foo.f90, var=X, line=15> : MAIN => FOO => BAR 
         1        180        180        180          0  malloc size <file=foo.f90, var=X, line=13>
         1        180        180        180          0  malloc size <file=foo.f90, var=X, line=13> : MAIN => FOO => BAR 
         4         80         16         49      22.69  malloc size <file=foo.f90, var=X, line=7>
         1         16         16         16          0  malloc size <file=foo.f90, var=X, line=7> : MAIN => FOO => BAR 
         3         80         48         60      14.24  malloc size <file=foo.f90, var=X, line=7> : MAIN => FOO => G => BAR 
---------------------------------------------------------------------------------------