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 character, 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
mallocandfreein the source code. -
The callpath for each occurrence of
mallocorfree. -
A list of all variable that were not deallocated in the source code.
![]() |
Note |
|---|---|
|
Due to the limitations of the |
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
---------------------------------------------------------------------------------------
![[Note]](note.png)