Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

debugging a code where memory usage is increasing

13 views
Skip to first unread message

amar Singh

unread,
Mar 18, 2012, 3:59:09 PM3/18/12
to
The code I am running is a MPI process with 4 cores. it appears that
there is a bug sitting in somewhere. Here's what I see:

as the code runs, its memory consumption increases. e.g. in the top
command %MEM
column increases in time. I suspect some variable is being allocated
but not deallocated but I am not sure what is going on.. any
suggestions to figure out would be appreciated. I used gfortran to
compile the code so I am looking at an appropriate compiler switch or
a strategy to use gdb or other debuggers to find what's going on.. the
code crashes when left to run for a long enough time.....

Andrew Haley

unread,
Mar 19, 2012, 6:50:24 AM3/19/12
to
You have a memory leak; that much is obvious.

We don't know what you know. Have you ever used gdb before? Any
debugger before? Have you any experience debugging large programs?
Etc...

Andrew.

amar Singh

unread,
Mar 19, 2012, 8:09:54 AM3/19/12
to
On Mar 19, 6:50 am, Andrew Haley <andre...@littlepinkcloud.invalid>
wrote:
I have used gdb and other debuggers. Of course, I know there is a
memory leak I want to know the gdb strategy to find which variable is
doing it.

Andrew Haley

unread,
Mar 19, 2012, 9:36:44 AM3/19/12
to
amar Singh <jagter...@gmail.com> wrote:
> On Mar 19, 6:50?am, Andrew Haley <andre...@littlepinkcloud.invalid>
> wrote:
>> amar Singh <jagteraho2...@gmail.com> wrote:
>> > The code I am running is a MPI process with 4 cores. it appears that
>> > there is a bug sitting in somewhere. Here's what I see:
>>
>> > as the code runs, its memory consumption increases. e.g. in the top
>> > command %MEM
>> > column increases in time. I suspect some variable is being allocated
>> > but not deallocated but I am not sure what is going on.. any
>> > suggestions to figure out would be appreciated. I used gfortran to
>> > compile the code so I am looking at an appropriate compiler switch or
>> > a strategy to use gdb or other debuggers to find what's going on.. the
>> > code crashes when left to run for a long enough time.....
>>
>> You have a memory leak; that much is obvious.
>>
>> We don't know what you know. Have you ever used gdb before? Any
>> debugger before? Have you any experience debugging large programs?
>> Etc...
>
> I have used gdb and other debuggers. Of course, I know there is a
> memory leak I want to know the gdb strategy to find which variable is
> doing it.

Right. I don't think there's any way to debug this without some
alteration to the program. I would begin by defining a wrapper for
malloc() that traces and logs allocations (and free()) along with the
caller. Look for blocks that are never freed. Calling backtrace()
from your malloc() wrapper tells you who is doing the allocation.
(Maybe fortran uses its own malloc, and you'd have to wrap that
instead. But you get the idea.)

Andrew.

Leclerc

unread,
Mar 19, 2012, 9:51:50 AM3/19/12
to amar Singh
if you can use valgrind (www.valgrind.org), I'd start with it. Take a
look at the following link:

http://jblevins.org/log/valgrind

0 new messages