简体   繁体   English

fortran错误回溯导致where循环

[英]fortran error backtrace leads to a where loop

I am working on a large fortran code and before to compile with fast options (in order to perform test on large database), I usually compile with "warnings" options in order to detect and backtrace all the problems. 我正在处理大型的fortran代码,并且在使用快速选项进行编译(以便在大型数据库上执行测试)之前,通常会使用“警告”选项进行编译,以便检测并回溯所有问题。

So with the gfortran -fbacktrace -ffpe-trap=invalid,zero,overflow,underflow -Wall -fcheck=all -ftrapv -g2 compilation, I get the following error: 因此,使用gfortran -fbacktrace -ffpe-trap=invalid,zero,overflow,underflow -Wall -fcheck=all -ftrapv -g2编译,我得到以下错误:

Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
 #0  0x7fec64cdfef7 in ???
 #1  0x7fec64cdf12d in ???
 #2  0x7fec6440e4af in ???
 #3  0x7fec64a200b4 in ???
 #4  0x7fec649dc5ce in ???
 #5  0x4cf93a in __f_mod_MOD
    at /f_mod.f90:132
 #6  0x407d55 in main_loop_
    at main.f90:419
 #7  0x40cf5c in main_prog
    at main.f90:180
 #8  0x40d5d3 in main
    at main.f90:68

And the portion of the code f_mod.f90:132 is containing a where loop: 代码f_mod.f90:132的一部分包含一个where循环:

! Compute s parameter
do i = 1, Imax
   where (dprim .ne. 1.0)
      s(:,:,:, :) = s(:,:,:, :) +vprim(:,:,:, i,:)*dprim(:,:,:, :)*dprim(:,:,:, :)/(1.0 -dprim(:,:,:, :))
   endwhere
enddo

But I do not see any mistake here. 但我在这里看不到任何错误。 All the other locations are the calls of the subroutine leading to this part. 其他所有位置都是通向该部分的子例程的调用。 And of course, since it is a SIGFPE error, I have to problem at the execution when I compile gfortran -g1 . 当然,由于它是SIGFPE错误,因此我在编译gfortran -g1时必须在执行时遇到问题。 (I use gfortran 6.4.0 on linux) (我在Linux上使用gfortran 6.4.0)

Moreover, this error appears and disappears with the modifications of completely different part of the code. 此外,随着代码完全不同部分的修改,此错误会出现并消失。 Thus, the problem comes from this where loop ? 因此,问题出在哪里? Or from somewhere else and the backtrace is wrong ? 还是其他地方的回溯是错误的? If it is the case how can I find this mistake? 如果是这种情况,我怎么能找到这个错误?

EDIT: 编辑:

Since, I can not reproduce this error in a minimal example (they are working), I think that the problem comes for somewhere else. 由于我无法在一个最小的示例中重现此错误(它们正在工作),因此我认为问题出在其他地方。 But how to find the problem in a large code ? 但是如何在大代码中查找问题?

As the code is dying with a SIGFPE, use each of the individual possible traps to learn if it is a FE_DIVBYZERO, FE_INVALID, FE_OVERFLOW, or FE_UNDERFLOW. 由于代码即将死于SIGFPE,请使用每个单独的陷阱来了解它是FE_DIVBYZERO,FE_INVALID,FE_OVERFLOW还是FE_UNDERFLOW。 If it is an underflow, change your mask to '1 - dprim .ne. 如果是下溢,则将掩码更改为'1-dprim .ne。 0'. 0'。

PS: Don't use array section notation when a whole array reference can be used instead. PS:当可以使用整个数组引用代替时,请不要使用数组节符号。

PPS: You may want to compute dprim*drpim / (1 - dprim) outside of the do-loop as it is loop invariant. PPS:您可能要在do循环之外计算dprim * drpim /(1-dprim),因为它是循环不变的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM