使用 Absoft Fortran 但使用 gfortran 时代码在运行时崩溃

Code crashes at runtime with Absoft Fortran but not with gfortran

我是 运行 一个开始类似于下面代码的脚本。过去当我 运行 脚本 f90 -o fakefile fakefile.f 然后 ./fakefile 它起作用了,但现在它不起作用并且立即 returns 一个 segmentation fault (core dumped) 错误。当我使用 gfortran fakefile.f 然后 ./a.out 时,代码运行正常。我无法弄清楚使用这两种编译方法之间的差异是什么。

 program fakefile
   implicit real*8(a-h,o-z)
   parameter(im9=4320,jm9=2160)
   parameter(im1=360,jm1=180)
   parameter(im25=1440,jm25=720)
   parameter(nlt=2)
   real*4 rrs(im9,jm9,nlt)
   real*8 rrsa25(im25,jm25,nlt)
   real*8 area25(im25,jm25,nlt)
   real*8 rrsa1(im1,jm1,nlt)
   real*8 area1(im1,jm1,nlt)
   rrsa1  = 0.0
   area1  = 0.0
   rrsa25 = 0.0
   area25 = 0.0
   rrs = 0.0
   print *, rrs

 end

您的分段错误是由于您的大型数组导致堆栈溢出。这是 Absoft 和 Intel Fortran 编译器的常见问题。对于您的编译器 (Absoft),使用 -s 标志告诉编译器在堆而不是堆栈上分配数组。另一种方法是增加 shell 中的堆栈大小限制(可能受管理员限制)。

查看 Absoft 常见问题解答:当我声明大型数组(>8 MB 的变量)时,我得到一个 来自 Linux.

的分段违规

A. Use the "-s" compiler option (static storage) to move the data from the stack to the heap or use the ulimit command (ulimit is a bash command - the csh equivalent to 'ulimit -s' is 'limit stack') to raise the stack size limit

# ulimit -s 8192
# ulimit -s 32768
# ulimit -s 32768

Once raised the limit applies to the current process and any children of that process.