简体   繁体   English

在 fortran (gfortran) 中使用非常大的 arrays

[英]Using very large arrays in fortran (gfortran)

I'm working with very large arrays, so at first when I try to compile I get an warning due to stack size.我正在使用非常大的 arrays,所以起初当我尝试编译时,由于堆栈大小而收到警告。

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):这就是代码(它可能有小错误,但我认为这不是问题,因为当我使用小型 arrays 时,它运行正常):

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:这是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 

TL;DR;: Just ignore or silence the warning, it is pointless TL;DR;: 只是忽略或沉默警告,这是没有意义的

This warning comes as a new feature of gfortran 10. I find it to be just noise.这个警告是 gfortran 10 的一个新特性。我发现它只是噪音。 You do not have any single Fortran procedure in your code.您的代码中没有任何单个 Fortran 过程。 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).因此,没有递归运行程序的风险,也不需要对堆栈做任何事情(使用ulimit或不使用其他工具)。

Basically it says that the arrays were placed into the static storage.基本上它说 arrays 被放入 static 存储中。 That is a fixed part of memory.那是 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. static存储主程序数据或模块数据或公共块数据或类似数据没有问题。

Placing the data in the static storage makes the data effectively save .将数据放在static存储中,可以有效的save数据。 But main program data is save automatically by the Fortran standard.但主程序数据由 Fortran 标准自动save

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.)因此,我提交了一个错误报告: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98411 (我在报告之前先检查了重复项,但没有找到。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM