Stack overflow in Fortran 90

后端 未结 6 1379
旧巷少年郎
旧巷少年郎 2020-12-29 13:47

I have written a fairly large program in Fortran 90. It has been working beautifully for quite a while, but today I tried to step it up a notch and increase the problem size

6条回答
  •  醉话见心
    2020-12-29 14:18

    The only problem I ran into with a similar test code, is the 2Gb allocation limit for 32-bit compilation. When I exceed it I get an error message on line 419 in winsig.c

    2GB Allocation Limit Error

    Here is the test code

    program FortranCon
    
    implicit none
    
    ! Variables
    INTEGER :: IA(64), S1
    REAL(8), DIMENSION(:,:), ALLOCATABLE :: AA, BB
    REAL(4) :: S2
    INTEGER, PARAMETER :: N = 10960
    IA(1)=N
    IA(2)=N
    
    ALLOCATE( AA(N,N), BB(N,N) )
    AA(1:N,1:N) = 1D0
    BB(1:N,1:N) = 2D0
    
    CALL TEST(AA,BB,IA)
    
    S1 = SIZEOF(AA)                 !Size of each array
    S2 = 2*DBLE(S1)/1024/1024       !Total size for 2 arrays in Mb
    
    WRITE (*,100) S2, ' Mb'         ! When allocation reached 2Gb then
    100 FORMAT (F8.1,A)                 ! exception occurs in Win32
    
    DEALLOCATE( AA, BB )
    
    end program FortranCon
    
    
    SUBROUTINE TEST(AA,BB,IA)
    IMPLICIT NONE
    INTEGER, DIMENSION(64),INTENT(IN) :: IA    
    REAL(8), DIMENSION(IA(1),IA(2)),INTENT(INOUT) :: AA,BB
    
    ... !Do stuff with AA,BB        
    END SUBROUTINE
    

    When N=10960 it runs ok showing 1832.9 Mb. With N=11960 it crashes. Of course when I compile with x64 it works ok. Each array has 8*N^2 bytes storage. I don't know if it helps but I recommend using the INTENT() keywords for the dummy variables.

提交回复
热议问题