Fortran 有关「;forrtl:错误(65):浮动无效“;
我一直在调试模式下使用英特尔编译器13.1.3.192版运行大量Fortran代码(启用了Fortran 有关「;forrtl:错误(65):浮动无效“;,fortran,intel-fortran,infinity,floating-point-exceptions,Fortran,Intel Fortran,Infinity,Floating Point Exceptions,我一直在调试模式下使用英特尔编译器13.1.3.192版运行大量Fortran代码(启用了-O0-g-traceback-fpe3标志)。它给了我以下输出消息: ... ... forrtl: warning (402): fort: (1): In call to MPI_ALLGATHER, an array temporary was created for argument #1 forrtl: error (65): floating invalid Image
-O0-g-traceback-fpe3
标志)。它给了我以下输出消息:
... ...
forrtl: warning (402): fort: (1): In call to MPI_ALLGATHER, an array temporary was created for argument #1
forrtl: error (65): floating invalid
Image PC Routine Line Source
arts 00000000016521D9 pentadiagonal_ser 385 pentadiagonal.f90
arts 0000000001644862 pentadiagonal_ 62 pentadiagonal.f90
arts 00000000004DF167 implicit_solve_x_ 1201 implicit.f90
arts 0000000000538079 scalar_bquick_inv 383 scalar_bquick.f90
arts 00000000004EFEAC scalar_step_ 190 scalar.f90
arts 0000000000401744 simulation_run_ 182 simulation.f90
arts 0000000000401271 MAIN__ 10 main.f90
arts 0000000000400FAC Unknown Unknown Unknown
arts 000000000420E444 Unknown Unknown Unknown
arts 0000000000400E81 Unknown Unknown Unknown
误差来源于子程序五对角_序列,用于求解五对角矩阵:
subroutine pentadiagonal_serial(A,B,C,D,E,R,n,lot)
use precision
implicit none
integer, intent(in) :: n,lot
real(WP), dimension(lot,n) :: A ! LOWER-2
real(WP), dimension(lot,n) :: B ! LOWER-1
real(WP), dimension(lot,n) :: C ! DIAGONAL
real(WP), dimension(lot,n) :: D ! UPPER+1
real(WP), dimension(lot,n) :: E ! UPPER+2
real(WP), dimension(lot,n) :: R ! RHS - RESULT
real(WP), dimension(lot) :: const
integer :: i
if (n .eq. 1) then
! Solve 1x1 system
R(:,1) = R(:,1)/C(:,1)
return
else if (n .eq. 2) then
! Solve 2x2 system
const(:) = B(:,2)/C(:,1)
C(:,2) = C(:,2) - D(:,1)*const(:)
R(:,2) = R(:,2) - R(:,1)*const(:)
R(:,2) = R(:,2)/C(:,2)
R(:,1) = (R(:,1) - D(:,1)*R(:,2))/C(:,1)
return
end if
! Forward elimination
do i=1,n-2
! Eliminate A(2,i+1)
const(:) = B(:,i+1)/(C(:,i)+tiny(1.0_WP))
C(:,i+1) = C(:,i+1) - D(:,i)*const(:)
D(:,i+1) = D(:,i+1) - E(:,i)*const(:)
R(:,i+1) = R(:,i+1) - R(:,i)*const(:)
在哪一行
const(:) = B(:,i+1)/(C(:,i)+tiny(1.0_WP))
导致错误的原因。我试着打印出const(:)
的值,发现确实存在Infinity
值。然而,我不明白为什么它能产生无穷大。据我所见,为了避免分母为零,将tiny(1.0wp)
添加到C(:,I)
中,现在分母几乎不可能为零。。。我还检查了当调用此子例程时,所有内容都将初始化或在声明后给定一个值。因此,我无法找出哪里会出错。(评论中有答案。请参阅。评论中有很多聊天,很难提取实际答案,但OP表明问题已经解决。)
@塞斯莫顿写道:
如果
C
的任何值都在-tiny
附近,那么分母仍然可以为零
您是否打印了
C
的值?小值是否与常量中的无穷大相关
@亚历山大·沃格特写道:
嗯,向无穷大中添加某些内容会导致浮点异常。。。我不确定ifort是否能检测到被无穷除法是零,我想这是另一个浮点例外!您最好确保C中没有出现无限值
@斯特凡写道:
解决方法:MKL/Lapack的例行程序gbsv如何?
然后,最后一个提示:尝试使用gfortran
编译。不同的编译器会创建不同的编译时/运行时警告和/或错误,可能gfortran
会更早地检测到您的问题
如果
C
的任何值都在-tiny
附近,那么分母仍然可以为零。是的,这是真的。但我想发生这种情况的可能性很小。或者,您是否有办法避免这种情况?您是否打印了C
的值?小值是否与常量中的无穷大相关?好吧,C(:,i)中有“-无穷大”值,但C(:,i)在分母中,这让我感到困惑…C的最小值大于0.1