Fortran array memory management

I am working on optimizing Fortran's fluid flow and heat transfer analysis program. When I try to run the simulation of large and large cells, I run into memory limitation problems. However, the grid is not that big. Only 500,000 cells and small peanuts for a typical CFD code to run. Even when I request 80 GB of memory for my problem, it crashes due to insufficient virtual memory.

I have a few guesses about which arrays are digging all this memory. In particular, it stands out (28801.345600). Correct me if I am mistaken in my calculations, but the array with double precision is 8 bits per value. So the size of this array will be 28801 * 345600 * 8 = 79.6 GB?

Now I think that most of this array ends with zeros in all calculations, so we do not need to store them. I think I can change the solution algorithm only to store non-zero values ​​to work in a much smaller array. However, I want to make sure that I look at the correct arrays to reduce their size. So, first I correctly calculated the size of the array above? And secondly, is there a way I can have a Fortran array size in MB or GB at runtime? In addition to listing most memory intensive arrays, I would be interested to see how code memory requirements change at run time.

+7
source share
1 answer

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.

+4
source

All Articles