use large array on Windows

I want to allocate a big matrix in my Fortran code running on Windows system.
The matrix is 7812500 by 400 with data type integer(4).

I am getting segmentation fault because the matrix is too large.

On linux machines, the issue was fixed by adding -mcmodem=medium and -Mlarge_arrays.

Are there options for windows systems to fix this large array issue?


Hi Guanfeng,

Windows does not support the medium memory model so unfortunately “-mcmodel=medium” is not available, however “-Mlarge_arrays” is. The difference is that “-mcmodel=medium” allows for static arrays larger than 2GB, while “-Mlarge_arrays” allows for large dynamic arrays. So long as you’re using Fortran allocatable arrays, you can still use large arrays on Windows.


Thanks a lot, Mat.

-Mlarge_arrays forces the compiler to use 64-bit integer math to calculate
the internal array-index-to-byte-offset calculation.

So make sure any index variables be integer*8. btw, you can write
code that works on both Windows and Linux by using dynamic allocation at runtime.

For example, statically allocating arrays of large size

parameter (size=16000)
parameter (m=size,n=size)
real*8 a(m,n), b(m,n), c(m,n), d


integer8 m,n
parameter (size=16000)
parameter (m=size,n=size)
double precision, dimension(2),allocatable::a(:,:),b(:,:),c(:,:)
8 d, walltime

allocate(a(m,n),b(m,n), c(m,n))

and combined with -Mlarge_arrays, should be able to handle large