gfortran IEEE异常不正确 [英] gfortran IEEE exception inexact

查看:573
本文介绍了gfortran IEEE异常不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在新的64b机器中使用了gfortran(5.3.1),Fedora 23。使用简单的gfortran -o编译(我们不使用-ffpe-trap选项!),激发古典平凡警告:

 注意:以下浮点异常是信号:IEEE_INVALID_FLAG 

由于INEXACT异常2.0 / 3.0)。 DDD调试器指向一个实常数(180d0 / pi; pi = 3.141518 ...)。我们不明白为什么这个标志出现,使用这个基本的编译,因为这些例外是一直到达...



这里的一些代码:

  Implicit none!real * 8(啊,oz)
real * 8 pi,dpi,radgra,TSI,TOL,xlsol,fi ,W
整数年,T1,k,m

打开(10,file ='stof-elem.sol')

pi = 4.d0 * datan(1.d0)
dpi = 2.d0 * pi
radgra = 360.d0 / dpi !!!!!!!!这里指出的例外!!!!!!!!!!

T1 = -9998!800d0!1450d0!

TSI = 1360.d0!1364.5d0!1367d0

TOL = 0.7d0 / radgra!不要使用更小的

C ...输出文件的名称
打开(12,file ='midmonth-2000.sal')

C-- -------------------------------------------------- -------------------
k = 0!输出计数器

写(12,*)T1

DO m = 1,12! select month
IF(T1.lt.0)then
xlsol =(270.d0 - dble(m-1)* 30.d0)/ radgra!from Dec
if(xlsol。 (xlsol.lt.0d0)xlsol = xlsol = xlsol + d
ELSE
xlsol = dble(m-3)* 30.d0 / radgra! + dpi
ENDIF

CALL MEANINSOLA(pi,dpi,radgra,TOL,T1,TSI,xlsol,fi,k,W)

rewind(10) !更好的倒带...
ENDDO

写(*,*)'输出:',k,'lines'

EXCEPTION出现在RADGRA ...的定义中,如图所示。如果重新定义常量(即,RADGRA = 57.2d0),则异常使用RADGRA ...移除到另一部分...等等...

解决方案

根据 https://gcc.gnu.org /ml/fortran/2013-06/msg00072.html ,执行 STOP 语句后,Fortran标准要​​求打印这些注释。


如果任何异常(14)在该映像上发信号,处理器将
发出一条警告,指出哪些异常是信号;这个
警告应在由命名常量ERROR
UNIT(13.8.2.8)标识的单位上。


您可以控制此请参阅 -ffpe-summary = -Options.htmlrel =nofollow>手册。默认情况下,显示所有异常的摘要,但显示不精确。你是否在某处启用了自己的错误?



为什么异常信号是一个不同的事情,你必须检查你的代码是否是你应该担心的事情。可能你不应该,不精确的浮点运算是非常常见的



由于消息是由 STOP 语句,一个简单的方法来摆脱这些消息是不要通过 STOP 语句终止你的程序,但让它达到 END PROGRAM


We are using gfortran (5.3.1), Fedora 23, in a new 64 b machine. Compiling with simple gfortran -o (we are not using -ffpe-trap options !), excites the "classical- trivial" warning:

Note: The following floating-point exceptions are signalling: IEEE_INVALID_FLAG 

Its due to INEXACT exception (type 2.0/3.0). The DDD debugger points towards a real constant (180d0/pi; pi = 3.141518...). We don't understand why this flag appears, with this basic compilation, because these exceptions are reached all the time...

Some code here:

    Implicit none !real*8(a-h,o-z)   
    real*8 pi,dpi,radgra,TSI,TOL,xlsol,fi,W      
    Integer year, T1, k,m

      open(10,file='stof-elem.sol') 

          pi = 4.d0 * datan(1.d0)
         dpi = 2.d0 * pi
       radgra = 360.d0 / dpi !!!!!!!! HERE POINTS THE EXCEPTION!!!!!!!!!!

         T1 = -9998 !800d0 !1450d0 !

        TSI = 1360.d0 !1364.5d0 !1367d0 

        TOL = 0.7d0 / radgra ! dont' use smaller 

C...Name of the output file
      open(12,file='midmonth-2000.sal')

C-----------------------------------------------------------------------
            k = 0 ! outputs counter

            write(12,*)T1            

      DO m = 1, 12  ! select month
           IF(T1.lt.0) then
             xlsol = (270.d0 - dble(m-1) * 30.d0) / radgra !from Dec
               if(xlsol.lt.0d0) xlsol = xlsol + dpi
           ELSE
              xlsol = dble(m-3) * 30.d0 / radgra !from Jan
               if(xlsol.lt.0d0) xlsol = xlsol + dpi
           ENDIF 

            CALL MEANINSOLA(pi,dpi,radgra,TOL,T1,TSI,xlsol,fi,k,W)

            rewind(10) ! better rewind...
      ENDDO

       write(*,*) 'Outputs:', k,'lines'

The EXCEPTION appears at the definition of RADGRA ... as indicated. If redefine the constant (i.e.,, RADGRA = 57.2d0), the exception migrates to another parts using RADGRA... and so on...

解决方案

As per https://gcc.gnu.org/ml/fortran/2013-06/msg00072.html the Fortran standard requires printing of these notes after executing the STOP statement.

"If any exception (14) is signaling on that image, the processor shall issue a warning indicating which exceptions are signaling; this warning shall be on the unit identified by the named constant ERROR UNIT (13.8.2.8)."

You can control this behaviour by -ffpe-summary=, consult you compiler's manual. By default, a summary for all exceptions but ‘inexact’ is shown. Have you enabled inexact yourself somewhere?

Why is that exception signalling is a different matter, you must examine your code whether it is something you should be worried about or not. Probably you should not, inexact floating point operations are very common.

Because the message is invoked by the STOP statement, a simple way to get rid of these messages is to not terminate your program by a STOP statement, but let it reach the END PROGRAM.

这篇关于gfortran IEEE异常不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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