Fortran算术异常

dmo*_*mon 2 fortran gfortran

这是一个简短的问题,但我试图尽可能详细地提供.

我正在编译一个旧的,但仍然积极开发的fortran代码(f77标准)在Scientific Linux上.这段代码的推荐编译器是ifort和gfortran.使用gfortran我可以编译并运行此代码.但是,如果我使用DEBUG = 1标志进行编码,则代码会编译,但会以SEG FAULT终止.单步执行gdb会导致以下错误来源:

REAL*4 TIME_CURRENT     
CALL CPU_TIME(TIME_CURRENT) 
ISECS = 100*INT(TIME_CURRENT)  
Run Code Online (Sandbox Code Playgroud)

该计划终止于:

Program received signal SIGFPE, Arithmetic exception. 
timer (init=1, isecs=0) at myprog.f:1818
1818 ISECS = 100*INT(TIME_CURRENT)
Run Code Online (Sandbox Code Playgroud)

如果我在第1818行停止执行并检查ISECS和TIME_CURRENT,我得到:

(gdb) ptype(TIME_CURRENT)
type = real(kind=4)
(gdb) ptype(ISECS)
type = integer(kind=4)
Run Code Online (Sandbox Code Playgroud)

我试过更具体和使用:

ISECS = 100*INT(TIME_CURRENT,4)
Run Code Online (Sandbox Code Playgroud)

但它没有帮助.我没有看到这可能等同于算术错误?

我的(生成文件生成)调试编译标志是:

gfortran -fno-automatic -m32 -O0 -g \
         -ffpe-trap=invalid,zero,overflow,underflow,precision -static-libgfortran
Run Code Online (Sandbox Code Playgroud)

当我编译出调试时,我不再收到SEG FAULT但是我的编译标志是

gfortran -fno-automatic -m32 -O2 -ffast-math -static-libgfortran
Run Code Online (Sandbox Code Playgroud)

我不是一个强大的程序员,所以任何帮助将不胜感激.请注意,我正在64位系统上进行编译,但强制进行32位编译,因为这是必需的.

Vla*_*r F 9

您的代码看起来不像FORTRAN 77,CPU_TIME来自Fortran 95.无论如何,您的调试选项非常严格.-ffpe-trap=invalid,zero,overflow,underflow,precision意味着浮点运算的许多合法用法都会导致异常.我建议只使用-ffpe-trap=invalid,zero,overflow.

具体来自gfortran手册:

Some of the routines in the Fortran runtime library, like CPU_TIME ,
are likely to trigger floating point exceptions when "ffpe-trap=precision"
is used. For this reason, the use of "ffpe-trap=precision" is not recommended.
Run Code Online (Sandbox Code Playgroud)