【发布时间】: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