jing-qian 发表于 2011-4-28 11:58:01

Ask for help!

I have a very simple program like the following. When I run this code under Visual Studio 2008 with Intel Fortran 11, it reports error of stack overflow.If I define array m as "integer m(512, 512)" but not "integer m(k(1),k(2))", the code works well. My system is Windows XP 32, and RAM is 1GB. It should not be the problem of memory. Can someone help me?


program test

IMPLICIT REAL(A-H, O-Z)

integer k(2)
common /index/ k

k(1) = 512
k(2) = 512

call dary

end program test

subroutine dary

IMPLICIT REAL(A-H, O-Z)
integer k(2)
common /index/ k

integer m(k(1),k(2))

m(1,1) = 2
write(*,*) m(1,1)

end subroutine dary

penultimate 发表于 2011-4-28 14:38:53

integer m(k(1),k(2))
语法错误,这是个编译时就要确定空间的语句,你在运行时才赋值。
FORTRAN的编译器越来越差啦,这条语句在编译时就应该报错才对。

jing-qian 发表于 2011-4-28 21:44:40

LZ, many thanks. But I still have some question. See, k(1:2) had been declared in common block and also had been defined in main program. The definition of array "integer m(k(1), k(2))" should be fine. In main program, I tried to change "k(1:2) = 500" and the code worked well. That's why I am so confused .
Could you please give me more help?

jing-qian 发表于 2011-4-29 01:43:15

I got help from others and I fixed the problem.

The computer may have 1GB of RAM, but the Microsoft linker defaults the stack size to 1MB.You have several choices:


1. In the Linker > System property pages, change the Stack Reserve Size to a larger value.100000000 (100 million) should be enough

2. Change the Fortran > Optimization > Heap Arrays property to 0, which causes such arrays to be allocated on the heap rather than on the stack

3. Change the code to:
integer, allocatable :: m(:.:)
allocate (m(k(1),k(2))
页: [1]
查看完整版本: Ask for help!