I have tracked down a severe memory leak in our large
Fortran electronic structure code, and the fault appears
to be that pgf90 is failing to deallocate an array on
subroutine exit as demanded by Fortran 95. The
array inquestion is declared as
real(kind=8), allocatable, dimension(:,:) :: arr
within a subroutine inside a module. It is allocated
conditionally depending on the vaues of various
subroutine arguments. The Fortran 95 standard requires
that this array be automatically deallocated upon exit
from the subroutine.
I am sure that the pgf90-generated code is simply failing to issue a deallocate for this array at subroutine exit. My evidence is that.
a) Using the google perftools heap profiler narrows the allocated
memory down to this particular subroutine, ans shows a mismatch
b) If I add an explicit DEALLOCATE statement and recompile the
memory leak disappears and the process memory size does
c) Even with the memory leak present the correct results are
My attempts to boil this down to a simple test case have failed to
reproduce the problem. In my attempts to make a simple test case
arrays are automatically deallocated on exit as they should be.
I don’t know how to take this any further. The code is far too complex
and so far from being self contained that it would be useless as a
bug report. The problem happens at any optimisation level, even -O0
so I don’t think it can be an optimiser code path issue. Clearly something in the larger code is interfering with the automatic deallocation, but I can not see what this could be.
Has anyone else seen any similar behaviour? And any suggestions for
testcases are welcome.