关于子程序内存的问题
小弟以前写了一个Tecplot后处理的程序。一开始写的时候,由于针对的都是100*100以内的网格,就没用module,在子程序内几个动态数组来算。后来碰到了600*300左右的网格,程序一跑就报错,都是调用这个子程序的那个地方overflow了。于是想着内存出问题就减内存,于是把integer的数组改成了integer(kind=2)来跑。结果跑起来了。再后来遇到了600*600左右的网格,由于integer(kind=2)已经是极限了,看了半天没法削,结果把子程序内的数组用module封装了起来,结果跑起来了。
在这想问一下,为什么这些数组封装在子程序内就会溢出,而封装在module内由子程序调用就能跑呢?子程序的内存大小是有什么限制么?这个限制能否调节?怎么调?
overflow可能是栈溢出,也可能是浮点溢出,最好截个图来看。 li913 发表于 2017-4-3 22:01
overflow可能是栈溢出,也可能是浮点溢出,最好截个图来看。
是堆栈溢出。报错信息是:Program exception - stack overflow
报错位置是我调用子函数的地方。
程序在mx=30, my=30和mx=300, my=300的时候可以运行,一旦mx=600, my=600左右就报错说stack overflow了。
以下是程序开头的部分:
subroutine tecplotFE_number(Mx,My,Flg,ff)
use tec_2D_number
use tec_temp_number
! ======== for tecplot output: type=Fequadrilateral ==================
!_______ 1
!| |
!| flg |
!| |
!------- MY
!1 ... MX
! ====================================================================
implicit none
integer::I,J,K,K1,K2
integer,intent(in)::MX,MY
real(kind=8),intent(in)::flg(Mx-1,My-1)
real(kind=8)::err
logical::Fs,fe,fl
integer::IJx(MX,MY),IJy(MX,MY)
integer::II(4),JJ(4)
integer::ff !ff=1 : use tec_2D_number ff=2 : use tec_tmpnumber
! ======== temp ========
integer::node1
integer::elem1
integer,allocatable::OET1(:,:)
integer,allocatable::listNx1(:),listNy1(:)
integer,allocatable::listEx1(:),listEy1(:) 栈溢出看这里
FAQ之 常见错误分析
http://fcode.cn/guide-36-1.html li913 发表于 2017-4-4 09:38
栈溢出看这里
FAQ之 常见错误分析
http://fcode.cn/guide-36-1.html
谢谢指导。
试了一下上述方法,确实没有报错了。
为什么将子程序中的数组全部用module封装起来然后用use来调用就不会报错呢? 可能是module中变量的内存位置不同吧。你可以看看http://fcode.cn/guide-99-1.html li913 发表于 2017-4-4 10:55
可能是module中变量的内存位置不同吧。你可以看看http://fcode.cn/guide-99-1.html
受教了,总算搞清楚了。谢谢!
页:
[1]