有关"forrtl:错误(65):浮动无效"的问题 [英] Questions on "forrtl: error (65): floating invalid"
问题描述
我一直在调试模式下(启用 -O0 -g -traceback -fpe3
标志的情况下)使用英特尔编译器版本13.1.3.192运行巨大的Fortran代码.它给了我以下输出消息:
I've been running a huge Fortran code with Intel compiler version 13.1.3.192 under the debug mode (with -O0 -g -traceback -fpe3
flags being turned on). It gave me the following output message:
... ...
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
错误的根源来自子例程pentadiagonal_serial,该子例程用于求解五对角矩阵:
and the source of the error comes from the subroutine pentadiagonal_serial, which is to solve a penta-diagonal matrix:
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.0_WP)
添加到 C(:,i)
中,现在分母几乎不可能为零...我还检查了何时调用此子例程,初始化所有内容或在声明后给定值.所以我不知道哪里出了问题.
causes the error. I tried to print out the values of const(:)
and find that there did exist Infinity
values. However, I cannot understand why it can generate infinities. As far as I see, to avoid zero denominator, the tiny(1.0_WP)
is added to C(:,i)
and now it is nearly impossible for the denominator to be zero... I also checked when this subroutine is being called, everything is initialized or given a value after declaration. So I couldn't figure out where could go wrong.
推荐答案
(Answers in the comments. See Question with no answers, but issue solved in the comments (or extended in chat). There is a lot of chat in the comments and its hard to extract the actual answer, but the OP indicates it is solved. )
@SethMMorton写道:
@SethMMorton wrote:
如果
C
的任何值都在-tiny
附近,那么分母仍然可以以零结尾.
If any of the values of
C
are around-tiny
then you still can end up with zero in the denominator.
您是否打印出了 C
的值?较小的值是否与 const
中的无穷大相关?
Did you print out the values of C
? Do small values correlate to the infinities in const
?
@Alexander Vogt写道:
@Alexander Vogt wrote:
好吧,向无穷大添加一些东西会导致浮点异常……而且我不确定ifort是否可以检测到无穷大除以零,我想那是另一个浮点异常!您最好确保C内部不会出现无限值.
Well, adding something to infinity results in a floating point exception... And I'm not sure ifort can detect that a division by infinity is zero, I guess that is another floating point exception! You'd better make sure that no infinite values occur inside C.
@Stefan写道:
@Stefan wrote:
解决方法:MKL/Lapack中的常规
?gbsv
如何处理?然后,最后一个提示:尝试使用gfortran
进行编译.不同的编译器会产生不同的编译时/运行时警告和/或错误,并且gfortran
可能会更早地检测到您的问题.
Workaround: What about the routine
?gbsv
from MKL/Lapack? Then, one last hint: Try to compile withgfortran
. Different compilers create different compile-time/run-time warnings and/or errors and maybegfortran
detects your problem earlier.
这篇关于有关"forrtl:错误(65):浮动无效"的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!