Using very large arrays in fortran (gfortran)

Viewed 909

I'm working with very large arrays, so at first when I try to compile I get an warning due to stack size.

Warning is:

    4 | integer, dimension(n,5) :: temp1 
 1 Warning: Array ‘temp1’ at (1) is larger than limit set by ‘-fmax-stack-var-size=’, moved from stack to static storage.
 This makes the procedure unsafe when called recursively, or concurrently from multiple threads.
 Consider using ‘-frecursive’, or increase the ‘-fmax-stack-var-size=’ limit, or c – ...

That's the code (It may have small mistakes, but I don't think that's the problem, because when I use with small arrays it runs correctly):

program fecha
    implicit none
    integer, parameter :: n = 100000
    integer, dimension(n,5) :: temp1
    real, dimension(n) :: temp2

    integer, dimension(:), allocatable :: dia, mes, ano, hora, minuto
    real, dimension(:), allocatable :: abs1
!-------------------------------------------------------------------------
    integer :: i = 1
    integer :: iounit, ierr
    character*50 :: formato = '(i2,1x,i2,1x,i4,1x,i2,1x,i2,1x,f7.4)'

    allocate(dia(n), mes(n), ano(n), hora(n), minuto(n))
    allocate(abs1(n))
    dia = 0; mes = 0; ano = 0; hora = 0; minuto = 0; abs1 = 0.0
!-------------------------------------------------------------------------
    open (newunit = iounit, file = 'datos_elegidos.txt')
    read(iounit,*)

    do
        read(unit = iounit, fmt = formato, iostat = ierr) temp1(i,1), temp1(i,2), temp1(i,3), temp1(i,4), temp1(i,5), temp2(i)
        if (ierr /= 0) exit
        write(*,*) temp1(i,1), temp1(i,2), temp1(i,3), temp1(i,4), temp1(i,5), temp2(i)
        i = i + 1 
    end do
    i = i-1    
!-------------------------------------------------------------------------
    deallocate(dia, mes, ano, hora, minuto, abs1)
    allocate(dia(i), mes(i), ano(i), hora(i), minuto(i), abs1(i))

    dia(:i) = temp1(:i,1)
    mes(:i) = temp1(:i,2)
    ano(:i) = temp1(:i,3)
    hora(:i) = temp1(:i,4)
    minuto(:i) = temp1(:i,5)
    abs1(:i) = temp2(:i)

    !print*, dia
    close(iounit)

end program

This is part of the txt:

dia mes ano hora min abs370 

 3  6 2016  0  5  30.4570   
 3  6 2016  0 10  27.5388   
 3  6 2016  0 15  23.1983   
 3  6 2016  0 20  22.3339   
 3  6 2016  0 25  22.0864   
 3  6 2016  0 30  20.9339   
 3  6 2016  0 35  21.8094   
 3  6 2016  0 40  21.3255   
 3  6 2016  0 45  22.1972   
 3  6 2016  0 50  21.2331   
 3  6 2016  0 55  21.6099   
 3  6 2016  1  0  20.4057 
1 Answers

TL;DR;: Just ignore or silence the warning, it is pointless

This warning comes as a new feature of gfortran 10. I find it to be just noise. You do not have any single Fortran procedure in your code. Therefore, there is no risk of running your procedures recursively and no need to do anything to your stack (using ulimit or nay other tool).

Basically it says that the arrays were placed into the static storage. That is a fixed part of memory. But it is completely fine! There is nothing wrong with static storage for main program data or module data or common block data or similar.

Placing the data in the static storage makes the data effectively save. But main program data is save automatically by the Fortran standard.

I consider this warning for a main program to be a compiler defect. Accordingly, I have submitted a bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98411 (I checked for duplicates first, before reporting, but didn't find any.)

Related