Segmentation error when initializing a large array

Hi all,

I encounter with a problem when I am trying to initialize a large size zero arrays (x(2, 2800, 1600000)). I make it an allocatable array but still the segmentation fault message appears.

Here is my code:

program test
 integer(kind=1), allocatable :: x(:, :, :)
 allocate(x(2, 2800, 1600000))

 x = 0_1

end program

I’ve tried ulimit -s unlimited but it didn’t work. I am working on a workstation and I suppose it should have larger memory than 8.34GB. Could anyone help with this?


Hi Zejin,

For large dynamically allocated arrays (>2GB), you need to compile with the “-Mlarge_arrays” or “-mcmodel=medium” options. Since there’s extra overhead with managing larger arrays, we don’t enable this support by default.

Hope this helps,

Hi Mat,

Thanks for replying. This exactly solves my problem!
Thank you very much.


FYI - Mlarge_arrays switch tells the compiler to calculate its
array-index-to-byte-offset math using 64-bit integers instead of 32-bit.
The offset for x(1,1500,1400000) would be
115001400000*4(bytes per array element) which could go beyond
32-bit limits.

means to convert to an object file format that accepts large statically
allocated arrays. It usually runs slower, so allocate the big arrays
dynamically and avoid -mcmodel=medium, but use -Mlarge_arrays