# use large array on Windows

**URL:** <https://forums.developer.nvidia.com/t/use-large-array-on-windows/135079>\
**Category:** Legacy PGI Compilers (archived)\
**Created:** [October 24, 2016, 3:08am UTC](https://forums.developer.nvidia.com/t/use-large-array-on-windows/135079 "2016-10-24T03:08:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![guanfeng](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@guanfeng](https://forums.developer.nvidia.com/u/guanfeng)\
**Post date:** [October 24, 2016, 3:08am UTC](https://forums.developer.nvidia.com/t/use-large-array-on-windows/135079/1 "2016-10-24T03:08:30Z")

</div>

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?

Regards,  
Guanfeng

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [October 24, 2016, 7:55am UTC](https://forums.developer.nvidia.com/t/use-large-array-on-windows/135079/2 "2016-10-24T07:55:09Z")

</div>

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.

-Mat

---

<div class="post-metadata">

**Author:** ![guanfeng](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@guanfeng](https://forums.developer.nvidia.com/u/guanfeng)\
**Post date:** [October 25, 2016, 3:38pm UTC](https://forums.developer.nvidia.com/t/use-large-array-on-windows/135079/3 "2016-10-25T15:38:38Z")

</div>

Thanks a lot, Mat.

> [@mkcolg](#):
>
> 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.
> 
> -Mat

---

<div class="post-metadata">

**Author:** ![tull](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tull](https://forums.developer.nvidia.com/u/tull)\
**Post date:** [December 9, 2016, 2:09pm UTC](https://forums.developer.nvidia.com/t/use-large-array-on-windows/135079/4 "2016-12-09T14:09:12Z")

</div>

-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

Becomes

integer_8 m,n  
parameter (size=16000)  
parameter (m=size,n=size)  
double precision, dimension(2),allocatable::a(:,:),b(:,:),c(:,:)  
real_8 d, walltime  
…  
…  
allocate(a(m,n),b(m,n), c(m,n))  
  
  
and combined with -Mlarge\_arrays, should be able to handle large  
arrays.
