gfortran警告浮点异常 [英] gfortran warn on floating point exception
问题描述
我使用gfortran一些code。现在一段时间,我一直在用编译
I'm using gfortran for some code. For a while now, I've been compiling with
-ffpe-trap=zero,overflow,invalid
在试图追捕一些错误。这会导致我的程序立即停止执行。有些情况下FPE可能是确定等等之类的标志:
in an attempt to hunt down some bugs. This causes my program to cease execution immediately. There are some cases where the FPE might be OK and so a flag like:
-ffpe-warn=zero,overflow,invalid
将是非常有益的。是否gfortran(或任何其他编译器)提供了这样的事?如果不是,是否有任何变通办法?我现在的想法是创建一个C函数注册一个信号处理程序写出来的警告,虽然我不知道如何去这样做。
would be very useful. Does gfortran (or any other compiler) provide anything like this? If not, are there any workarounds? My current thought is to create a C function to register a signal handler to write out the warning, although I have no idea how to go about doing that.
推荐答案
我不知道在遇到一个浮点异常警告的方式。但无论gfortran和ifort有信号处理例程。例如,见信号的gfortran文件和
英特尔Fortran编译器<一个href=\"http://gcc.gnu.org/onlinedocs/gchttp://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/lin/main_for_lin.pdf\"相对=nofollow>用户和参考指南(警告:大PDF)。(见病房410页)
I don't know of a way of warning on encountering a floating point exception. But both gfortran and ifort have signal handling routines. See for example the gfortran documentation of signal and the Intel Fortran Compiler User and Reference Guides (warning: large PDF) (see page 410 on wards).
您可以建立一个呼叫信号下列操作之一信号
:
You can establish one of the following actions for a signal with a call to
signal
:
- 忽略指定的信号(由数字标识)。
- 使用的默认操作为指定的信号,这可以重置previously既定行动。
- 从指定的信号给过程控制转移到接收信号,通过名称指定。
在你的情况,你会想编写一个函数做一些事情,当一个浮点异常时(例如打印文件名/行号),并在上面的列表中使用第三个选项。
In your case, you would want to write a function to do something when a floating point exception occurs (e.g. print file name/line number), and use the third option in the above list.
可惜,这不是很便携:看看此页< /一>用于处理关于各种编译器的信号的例子。如果你想,你可以包装在preprocessor宏一些code到
Unfortunately this is not very portable: take a look at this page for examples of signal handling for various compilers. You could wrap some code in preprocessor macros if you want to
- 对多编译器编译
- 如果一些preprocessor标志设置只使用信号处理例程(参见<一个href=\"http://stackoverflow.com/questions/5473556/what-is-the-ndebug-$p$pprocessor-macro-used-for-on-different-platforms\"><$c$c>-NDEBUG$c$c>)
更新:最终, IEEE_EXCEPTIONS
内在模块的异常处理设施,将做到这一点的可移植的方法,如高性能马克建议
Update: Ultimately the exception handling facilities of the ieee_exceptions
intrinsic module would be the portable way to do this, as suggested by High Performance Mark.
这篇关于gfortran警告浮点异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!