简体   繁体   English

为什么不引发浮点异常 (FPE)?

[英]Why Floating Point Exception (FPE) is not raised?

I am trying to catch some FPE in a Fortran code, but it doesn't seems to work on every environment.我试图在 Fortran 代码中捕获一些 FPE,但它似乎并不适用于所有环境。

I wrote the following code as example:我写了下面的代码作为例子:

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

One of my machine (1) uses CentOS 7.6.1810, gfortran 4.8.5, and has an Intel Xenon as CPU.我的一台机器 (1) 使用 CentOS 7.6.1810、gfortran 4.8.5,并有一个 Intel Xenon 作为 CPU。 The other one (2) uses Debian 10 Buster (actually this one is on Windows 10, but I use the debian app for the WSL), gfortran 9.2.0 and has an Intel Core i5 as CPU.另一个 (2) 使用 Debian 10 Buster(实际上这个是在 Windows 10 上,但我使用 WSL 的 debian 应用程序),gfortran 9.2.0 并且有一个 Intel Core i5 作为 CPU。

When I compile the above code using当我使用编译上面的代码时

gfortran -o test -ffpe-trap=zero -fbacktrace -g -Og test.f90

on machine 1 and execute the code, I get what I expect, ie在机器 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

However, when I do the same thing on machine 2, I get only:然而,当我在机器 2 上做同样的事情时,我只得到:

$ ./test
start

Why?为什么? And what should I do to get the SIGFPE (and other signals) error message on machine 2?我应该怎么做才能在机器 2 上获得 SIGFPE(和其他信号)错误消息?

Installing WSL 2 solved the problem.安装WSL 2解决了这个问题。

$ ./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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM