【问题标题】:Using very large arrays in fortran (gfortran)在 fortran (gfortran) 中使用非常大的数组
【发布时间】:2021-03-30 17:04:54
【问题描述】:

我正在处理非常大的数组,所以起初我尝试编译时由于堆栈大小而收到警告。

警告是:

    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 – ...

这就是代码(它可能有小错误,但我认为这不是问题,因为当我使用小数组时它运行正确):

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

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

【问题讨论】:

  • 我在您的代码中没有看到任何特别大的数组。此外,您不要在此处“附加” .txt,而是复制并粘贴内容。至少有一部分。
  • @VladimirF 如何在此处附加 txt?我是这里的初学者
  • 然后查看How to Ask
  • @VladimirF。谢谢,我编辑它。
  • 文件真的包含那些空行吗?

标签: io segmentation-fault fortran gfortran


【解决方案1】:

TL;DR;:忽略警告或使警告静音,这是没有意义的

这个警告是 gfortran 10 的一个新特性。我发现它只是噪音。您的代码中没有任何单个 Fortran 过程。因此,没有递归运行程序的风险,也不需要对堆栈做任何事情(使用ulimit 或其他工具)。

基本上,它表示将数组放入静态存储中。那是内存的固定部分。但是完全没问题!主程序数据或模块数据或普通块数据等静态存储没有问题。

将数据放在静态存储中使数据有效save。但主程序数据为saveFortran标准自动。

我认为这个针对主程序的警告是编译器缺陷。因此,我提交了一个错误报告:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98411(我在报告之前先检查了重复项,但没有找到。)

【讨论】:

    猜你喜欢
    • 2014-05-30
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多