MEMORY_TEST
How Big Can Arrays Be?


MEMORY_TEST is a FORTRAN90 program which declares and uses a sequence of larger and larger arrays, to see what the memory limits are on a given computer.

The program tries an increasing series of values of N, using powers of 2, between limits that you set. At some point, the program may ask for more memory than can be provided, and crash. This is one way to find out what the memory ceiling is! The relevant power of 2 is likely to be in the 20's:
Log(N)N
201,048,576
212,097,152
224,194,304
238,388,608
2416,777,216
2533,554,432
2667,108,864
27134,217,728
28268,435,456
29536,870,912
301,073,741,824

Remember that your memory is probably described in terms of bytes, but that integers and reals require 4 bytes, and double precision reals require 8 bytes.

Problems with Large Arrays:

The use of very large arrays in a perfectly legal program can cause a failure that appears as a "segmentation fault".

This might be caused, for instance, by the use of automatic arrays in a subprogram. An automatic array is one whose dimension is passed into the subprogram as an argument, but whose memory is only created when the subprogram is entered. Some compilers, presumably expecting such arrays to be small, use memory from the stack; if the available memory is exceeded, the program crashes.

You might be able to make such an error go away by replacing the automatic arrays by explicitly allocated arrays. Their memory comes from the heap, which is, typically, a more substantial resource.

You could allocate the arrays in the calling program.

On Unix, you can determine the current stacksize, in kilobytes, by the command

        ulimit -S -s
      
My system reported the value as "8192". You can increase this limit to a numeric value:
        ulimit -S -s 16384
      
or simply ask that it be unlimited using the command:
        ulimit -s unlimited
      

Alternatively, your FORTRAN compiler may have a switch that controls the size of the stack, or that changes the method of getting memory for automatic arrays. For the Intel ifort compiler, the switch -heap-arrays [n] means that arrays larger than n will be assigned memory from the heap rather than the stack.

Usage:

memory_test log_n_min log_n_max
runs the program for sizes N = 2log_n_min to 2log_n_max.

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages:

MEMORY_TEST is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs:

LINPACK_BENCH, a FORTRAN90 program which measures the time needed to factor and solve a linear system.

MACHINE, a FORTRAN90 library which can return various machine constants.

MATMUL, a FORTRAN90 program which is an interactive matrix multiplication benchmark program.

MDBNCH, a FORTRAN77 program which is a benchmark code for a molecular dynamics calculation.

TIMER, a FORTRAN90 program which demonstrates how to compute CPU time or elapsed time.

Source Code:

Examples and Tests:

List of Routines:

You can go up one level to the FORTRAN90 source codes.


Last revised on 17 January 2011.