Reputation: 19
I am facing problems of stack overflow for my Fortran 90 program. I put all the parameters in module, and i got segment fault when running big examples, which makes me confused TAT. I have written a small program to verify my assumption of where the problem might be. I got some interesting phenomenon, and want to ask what is the principle of them.
I put an extremely large array in a module (etc. REAL a(10000000)
). When I use it in the subroutine, there won't be segment fault. Thus I am wondering where the storage of the array is?
I allocate an extremely large array (etc. allocate(a(10000000))
) in a subroutine A
, and transmit it into another subroutine B
. In B, I define it as a(10000000)
, and there won't be segment fault. Thus I am wondering what is transmitted between two subroutine of an allocatable array?
For my own complicated program, I have checked several times that I allocate every arrays in module, but the segment fault is still happened when example is getting large. I just want to know if there is something I'm missing which will influence the usage of stack.
Now, I have no idea where to check TAT, so is there anybody can give me some insight of debugging the segment fault with stack overflow? I will appreciate so much for that!
Upvotes: 0
Views: 186
Reputation: 29244
I am able to replicate the problem with Intel Fortran (oneAPI HPC kit, ifort
). To mitigate the problem I setup heap arrays when over 1000 kb in size.
The following test code
program Console2
use LU_MODULE
integer, parameter :: n = 359
real(wp) :: A(n,n), LU(n,n), b(n), x(n), delta
integer :: indx(n), d, ierr
call RANDOM_SEED()
call RANDOM_NUMBER(A)
call RANDOM_NUMBER(b)
A = 3*(A + eye(n)) ! Line 18, where error occus
print *, 'n=', n, ' mem=', sizeof(A)/1024, 'kb'
...
Fails when n>=359
without this setting.
forrtl: severe (170): Program Exception - stack overflow
Image PC Routine Line Source
FortranConsole2.e 00007FF7F363A727 Unknown Unknown Unknown
FortranConsole2.e 00007FF7F363509A MAIN__ 18 program.f90
FortranConsole2.e 00007FF7F3637E6E Unknown Unknown Unknown
FortranConsole2.e 00007FF7F363AA59 Unknown Unknown Unknown
FortranConsole2.e 00007FF7F363A97E Unknown Unknown Unknown
FortranConsole2.e 00007FF7F363A83E Unknown Unknown Unknown
FortranConsole2.e 00007FF7F363AACE Unknown Unknown Unknown
KERNEL32.DLL 00007FFC336A7034 Unknown Unknown Unknown
ntdll.dll 00007FFC33B42651 Unknown Unknown Unknown
but with the setting enabled I get the expected output
n= 359 mem= 1006 kb
...
Upvotes: 2