Dynamic memory allocation in fortran77

2019-05-30 14:51发布

问题:

I am writing a Fortran77 program which uses a 3-dimensional array. I am declaring the array as follows Array_E(0:500,0:1000,0:100). When I execute the program it crashes instantly saying that it is "killed". When I ran strace, what I got was,

execve("./yee", ["./yee"], [/* 65 vars */] +++ killed by SIGKILL +++

I suspect the problem is that the g77 compiler is not able to allocate memory for the array. In fact there are nine such arrays. In such a case is there a way to dynamically allocate memory on the stack in f77? If this is not the reason for the crash, kindly let me know if you have any idea about it.

回答1:

The array size is about 50x10^6 entries, so roughly 400 MBytes in size for double precision. 9 such arrays will take up 3.6 GBytes of memory, so I assume that you have enough memory available to begin with?

Using large arrays in Fortran 77 could be problematic, as they are not allocated dynamically but put on the stack. I'm not sure what the limits are, I guess it depends on the operating system and architecture, but on a 32 bit system it will probably not work to use arrays that are that large on the stack. You could resort to allocatable arrays of Fortran 90, but then you have to use gfortran instead of g77.

If you need to stick to strict fortran 77, you can use the ma package which can be obtained as part of the global arrays toolkit (http://www.emsl.pnl.gov/docs/global/).



标签: fortran77