GFortran相当于ieee_exceptions [英] GFortran equivalent of ieee_exceptions

查看:169
本文介绍了GFortran相当于ieee_exceptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个程序,该程序在执行无效操作时会停止,不管它如何与GFortran一起编译。使用ifort我可以这样做:

 使用ieee_exceptions 
....
logical :: halt
....
call ieee_get_halting_mode(IEEE_USUAL,halt)
call ieee_set_halting_mode(IEEE_USUAL,.True。)
....

....
call ieee_set_halting_mode(IEEE_USUAL,halt)

GFortran是否有类似于ifort的 ieee_exceptions 的模块?或者更好的方法是停止停止模式,而不知道如何编译程序或将使用哪个编译器? 解决方案

GFortran支持ieee_exceptions模块,就像GCC 5版本一样。



如果你坚持使用旧的GFortran版本,解决方法是在C / asm,获取/设置FP捕获状态寄存器并从Fortran中调用这些寄存器。



PS:GFortran确实有一个开关(-fpe-trap) FP例外情况,请参阅 http://gcc.gnu.org/onlinedocs/gfortran/ Debugging-Options.html 。但是,既然你明确地说过不管它是如何用gfortran编译的,我想你不想使用它。


I am trying to write a program that will stop whenever an invalid operation is performed, no matter how it is compiled with GFortran. With ifort I could do something like this:

use ieee_exceptions
....
logical      :: halt
....
call ieee_get_halting_mode(IEEE_USUAL,halt)
call ieee_set_halting_mode(IEEE_USUAL,.True.)
....
! Something that may stop the program
....
call ieee_set_halting_mode(IEEE_USUAL,halt)    

Does GFortran have a module similar to ifort's ieee_exceptions? Or even better is there a way of stopping the halting mode without knowing how the program will be compiled or which compiler will be used?

解决方案

GFortran supports the ieee_exceptions module as of the GCC 5 release.

If you're stuck on an older GFortran release, a workaround would be to implement functions in C/asm that get/set the FP trapping status register and call those from Fortran.

PS.: GFortran does have a switch (-fpe-trap) for globally enabling traps for FP exceptions, see http://gcc.gnu.org/onlinedocs/gfortran/Debugging-Options.html . But, since you explicitly said "no matter how it is compiled with gfortran", I guess you don't want to use that.

这篇关于GFortran相当于ieee_exceptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆