浮点异常在新 gfortran 版本中发出信号 [英] Floating-point exceptions are signalling in new gfortran version
问题描述
我目前正在调试我的老板在 90 年代写的一些软件的子程序.在特定子例程的 do 循环中似乎发生了浮点异常:
I am currently working to debug a subroutine of some software that my boss has written back in the 90s. There seems to be a floating-point exception that occurs in a do loop of a particular subroutine:
16 irad=1,incmax
rr1=rr2
rr2=rr2+rdiv
if(rr1.gt.rlimit) goto 16
if(pts(irad).gt.0.0) then
discrm=(rmsden(mt,irad)/pts(irad))
1 -((average(mt,irad)**2)/(pts(irad)**2))
else
discrm=0.0
endif
if(discrm.ge.0.0) then
rmsden(mt,irad)=sqrt(discrm)
else
rmsden(mt,irad)=0.0
endif
average(mt,irad)=average(mt,irad)/pts(irad)
average(mt,irad)=(average(mt,irad)*100.0)/bigmost(mt)
rmsden(mt,irad)=(rmsden(mt,irad)*100.0)/bigmost(mt)
denbot(mt,irad)=(denbot(mt,irad)*100.0)/bigmost(mt)
dentop(mt,irad)=(dentop(mt,irad)*100.0)/bigmost(mt)
iradmax(mt)=irad
17 if(iverbose0.ge.1) then
ipts=pts(irad)
iptszero=ptszero(irad)
if(ipts.eq.0) then
average(mt,irad)=0.0
rmsden(mt,irad)=0.0
denbot(mt,irad)=0.0
dentop(mt,irad)=0.0
endif
write(6,99) rr1,rr2,ipts,iptszero,average(mt,irad),
1 rmsden(mt,irad),denbot(mt,irad),dentop(mt,irad)
99 format(1x,2f9.2,2i8,2f8.1,2f8.1)
endif
16 continue
stop 'PIPPA'
If I put the stop 'PIPPA' statement before "16 continue", the there are no errors. However, if the stop statement goes after the "16 continue", I get:
Note: The following floating-point exceptions are signalling: IEEE_INVALID_FLAG
STOP PIPPA
在升级 GCC 编译器/库之前不会发生这种情况.我承认我通过谷歌搜索找到了很多资源,但我仍然无法调试这个.我也在编译时尝试了 --fpe-trap
标志,但是它们不输出任何东西.
This didn't happen before upgrading the GCC compilers/libraries. I admit that I have found a lot of resources through Googling, but I am still unable to debug this. I have also tried the --fpe-trap
flags upon compilation, however they do not output anything.
为什么 gfortran 现在抱怨?
Why does gfortran now complain?
推荐答案
这里好像有两个问题.让我们试着一一回答.
There seems to be two questions here. Lets try to answer each one.
1.为什么新的 GFortran 版本会打印这样的信息
由于 Fortran 2008 标准要求执行 STOP 和 ERROR STOP 语句输出当前信号 FP 异常的列表(如果系统支持这样的事情),GFortran 从 GFortran 版本 4.9 开始遵循这一点.请参阅 https://gcc.gnu.org/ml/fortran/2013-06/msg00072.html .
Since the Fortran 2008 standard requires that execution of the STOP and ERROR STOP statements outputs a list of currently signaling FP exceptions (if such a thing is supported by the system), GFortran follows this as of GFortran version 4.9. See https://gcc.gnu.org/ml/fortran/2013-06/msg00072.html .
<强>2.为什么我的代码会触发这个异常,为什么它只发生在新的 GFortran 版本中
很可能,异常之前也发出过信号,但由于它没有在 STOP 语句中打印,因此您没有意识到它.由于您展示的示例不是独立的(我无法编译和测试它),我只能建议您尝试通常的调试命令行选项,例如-fcheck=all, -ffpe-trap=invalid,零,溢出 -g -Wall -Wextra -Werror -pedantic",检查在 valgrind 等下运行你的程序.
Very likely, the exception was signalling before as well, but since it wasn't printed at the STOP statement you weren't aware of it. Since the example you have showed isn't self-contained (I can't compile and test it), I can only recommend you try the usual debugging command line options such as "-fcheck=all, -ffpe-trap=invalid,zero,overflow -g -Wall -Wextra -Werror -pedantic", check running your program under valgrind etc.
这篇关于浮点异常在新 gfortran 版本中发出信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!