Memory usage is a rather vague concept of virtual memory systems. You can allocate large amounts of memory (large size of virtual memory), but only a small part of it is actually actively used (small size of the resident set is RSS).
Unix systems provide the getrusage(2) system call, which returns information about the amount of system resources used by calling threads / processes / processes. In particular, it provides the maximum RSS value ever achieved since the start of the process. You can write a simple Fortran C-helper function that calls getrusage(2) and returns the value of the ru_maxrss field of the ru_maxrss structure.
If you work on Linux and don't care about portability, you can simply open and read from /proc/self/status . This is a simple text pseudo file that, among other things, contains several lines with statistics about the use of the virtual memory of the process:
... VmPeak: 9136 kB VmSize: 7896 kB VmLck: 0 kB VmHWM: 7572 kB VmRSS: 6316 kB VmData: 5224 kB VmStk: 88 kB VmExe: 572 kB VmLib: 1708 kB VmPTE: 20 kB ...
An explanation of the various fields is here . You are most interested in VmData , VmRSS , VmHWM and VmSize . You can open /proc/self/status as a regular file with OPEN() and fully process it in Fortran code.
See also what memory limits are set using ulimit -a and ulimit -aH . You may have exceeded the hard virtual memory limit. If you submit jobs through the Distributed Resource Manager (for example, SGE / OGE, Torque / PBS, LSF, etc.), make sure you request enough memory for the job.
Hristo iliev
source share