Dynamic memory allocation in fortran77

匆匆过客 提交于 2019-12-08 05:34:09

问题


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/).



来源:https://stackoverflow.com/questions/3834985/dynamic-memory-allocation-in-fortran77

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!