Fortran 为什么不引发浮点异常(FPE)?
我试图在Fortran代码中捕获一些FPE,但它似乎并不适用于所有环境 我编写了以下代码作为示例:Fortran 为什么不引发浮点异常(FPE)?,fortran,gfortran,windows-subsystem-for-linux,Fortran,Gfortran,Windows Subsystem For Linux,我试图在Fortran代码中捕获一些FPE,但它似乎并不适用于所有环境 我编写了以下代码作为示例: program test implicit none doubleprecision, dimension(1) :: x ! used to lure the compiler x(1) = 1d0 print *, 'start' print *, 1d0 / (1d0 - x(1)) print *, 'end' end program
program test
implicit none
doubleprecision, dimension(1) :: x ! used to lure the compiler
x(1) = 1d0
print *, 'start'
print *, 1d0 / (1d0 - x(1))
print *, 'end'
end program test
我的一台机器(1)使用CentOS 7.6.1810、gfortran 4.8.5,并使用Intel Xenon作为CPU。另一个(2)使用Debian 10 Buster(实际上这一个是在Windows 10上,但我使用的是用于WSL的Debian应用程序),gfortran 9.2.0,并使用Intel Core i5作为CPU
当我使用
gfortran-o test-ffpe trap=zero-fbacktrace-g-Og test.f90
在机器1上执行代码,我得到了我所期望的,即
$ ./test
start
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
#0 0x7F2374BEC697
#1 0x7F2374BECCDE
#2 0x7F23740E827F
#3 0x400858 in MAIN__ at test.f90:9
但是,当我在机器2上执行相同的操作时,我只得到:
$ ./test
start
为什么??我应该怎么做才能在机器2上获得SIGFPE(和其他信号)错误消息?安装解决了问题
$ ./test
start
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
#0 0x7feab2aee8b0 in ???
#1 0x7feab2aedae3 in ???
#2 0x7feab276883f in ???
at /build/glibc-vjB4T1/glibc-2.28/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
#3 0x4011fb in test
at /home/user/test/test.f90:9
#4 0x401299 in main
at /home/user/test/test.f90:11
Floating point exception
安装解决了这个问题
$ ./test
start
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
#0 0x7feab2aee8b0 in ???
#1 0x7feab2aedae3 in ???
#2 0x7feab276883f in ???
at /build/glibc-vjB4T1/glibc-2.28/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
#3 0x4011fb in test
at /home/user/test/test.f90:9
#4 0x401299 in main
at /home/user/test/test.f90:11
Floating point exception
欢迎光临,我建议您坐飞机。请对所有Fortran问题使用tag。我确实用GCC 9.21 OpenSUSE 15.0捕获了它。也许是WSL的错?相关的?您似乎需要询问Microsoft如何处理WSL下的浮动异常。我怀疑您需要熟悉IEEE_算术内在模块。虽然您没有看到错误消息,但看起来仍然存在中止。这是你关心的信息吗?@VladimirF和evets谢谢。这似乎确实与WSL有关。显然,这是一个可以用WSL2解决的老问题。我真的不想加入Windows Insider程序,所以我还不能测试这是否真的解决了我的问题。欢迎,我建议参加。请对所有Fortran问题使用tag。我确实用GCC 9.21 OpenSUSE 15.0捕获了它。也许是WSL的错?相关的?您似乎需要询问Microsoft如何处理WSL下的浮动异常。我怀疑您需要熟悉IEEE_算术内在模块。虽然您没有看到错误消息,但看起来仍然存在中止。这是你关心的信息吗?@VladimirF和evets谢谢。这似乎确实与WSL有关。显然,这是一个可以用WSL2解决的老问题。我真的不想加入Windows Insider程序,所以我还不能测试这是否真的解决了我的问题。