- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
is there a way to know the amount of memory used by a program at
some specific location? I think that one possibility would be a system
call to "top" or analogous tools, but I wonder whether there is
already some library function provided by the compiler for this.
Thank you,
Marco Restelli
is there a way to know the amount of memory used by a program at
some specific location? I think that one possibility would be a system
call to "top" or analogous tools, but I wonder whether there is
already some library function provided by the compiler for this.
Thank you,
Marco Restelli
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
At least on Unix-type systems, the command "size" should give you some information. It won't help much if you have dynamically allocated memory, however.
Thomas
Thomas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't have the best method, but 2 things I have used in the past:
If you want to check at some point of your program, you could try this:
USE IFPORT
integer :: reslt
....when you want the memory statistics ....
reslt = system( "/bin/date >> memory_trace.txt ; /usr/bin/vmstat >> memory_trace.txt" )
and then examine the file after the run OR open the file with a normal Fortran OPEN and read the data. This is the TOTAL system statistic but in most cases your code is the only important code running on the system. You could run 'date ; vmstat' just before starting your code to get a baseline before the code starts.
If you have a server or server farm, you should consider installing GANGLIA, which records this information and more, has a nice web interface, and gives you nice charts.
We do have a feature request for a Fortran callable function to return this information at runtime. It is complicated by Linux's memory management and lazy-page philosophy. Without going down Alice's rabbit hole, when you ALLOCATE memory the OS doesn't actually do anything until you physically touch those pages (with initialization or access). On the opposite side, when you DEALLOCATE, linux may keep those pages around for you for a while, assuming that you may want to reuse them again sometime soon. So it's hard to get a handle on your high water mark like we used to be able to get in the 'good old days' before virtual memory.
and 'size myprog.exe' will do a great job of showing your static data needs, so if your code is old school F77 this may be all you need. 'size' does not capture any of your dynamically allocated data needs, however.
ron
If you want to check at some point of your program, you could try this:
USE IFPORT
integer :: reslt
....when you want the memory statistics ....
reslt = system( "/bin/date >> memory_trace.txt ; /usr/bin/vmstat >> memory_trace.txt" )
and then examine the file after the run OR open the file with a normal Fortran OPEN and read the data. This is the TOTAL system statistic but in most cases your code is the only important code running on the system. You could run 'date ; vmstat' just before starting your code to get a baseline before the code starts.
If you have a server or server farm, you should consider installing GANGLIA, which records this information and more, has a nice web interface, and gives you nice charts.
We do have a feature request for a Fortran callable function to return this information at runtime. It is complicated by Linux's memory management and lazy-page philosophy. Without going down Alice's rabbit hole, when you ALLOCATE memory the OS doesn't actually do anything until you physically touch those pages (with initialization or access). On the opposite side, when you DEALLOCATE, linux may keep those pages around for you for a while, assuming that you may want to reuse them again sometime soon. So it's hard to get a handle on your high water mark like we used to be able to get in the 'good old days' before virtual memory.
and 'size myprog.exe' will do a great job of showing your static data needs, so if your code is old school F77 this may be all you need. 'size' does not capture any of your dynamically allocated data needs, however.
ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thomas, Ron, thank you for the indications, I will experiment with
vmstat and possibly GANGLIA as well. In fact, what I want to check is
almost completely dynamically allocated memory, either by explicit
ALLOCATE statements or by temporaries, automatic variables, derived
type copies and so on.
I understand the difficulties you mention in doing this by a fortran
callable function... I guess this is why we would be so happy if the
compiler writers took care of it :-).
Marco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Marco, why don't you look into /proc//* for dynamic processinformation. For sure it is in there somewhere. Sorry I can't give you the exact location, some investigation is required.
I don't think vmstat will give you process specific information. michael
I don't think vmstat will give you process specific information. michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should try pmap. It will give you the breaking of the memory usage for your process. Try the -d flag (-x flag is also interesting)

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page