How can I make gfortran or ifort tell me when it implicitly promotes a REAL(4) to a REAL(8)?

懵懂的女人 提交于 2019-11-30 09:38:51

问题


I am tasked with changing the precision of parts of an HPC application, bearing in mind that it makes heavy reliance on auto-vectorisation. It is therefore useful for the compiler to inform me when conversions of any type of floating point conversion occurs (as this could have a serious performance impact).

The -Wconversion flag sounds like it should suit my needs:

-Wconversion

Warn about implicit conversions between different types.


https://gcc.gnu.org/onlinedocs/gcc-4.1.0/gfortran/Warning-Options.html

However, in practice, gfortran 5.2.0 only appears to report floating point demotions, e.g. REAL(8) to REAL(4).

GCC has the -Wdouble-promotion flag - exactly what I need, but not available for gfortran. (https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html)

I am developing with gfortran, but ifort is available to me. However, I can't find any similar arguments for -warn (https://software.intel.com/en-us/node/525184).

How can I get either of these compilers to emit a warning when implicitly promoting a REAL?


回答1:


You refer to using gfortran 5.2.0, so let's look at the documentation for that version rather than 4.1.0. This has two relevant flags for what you consider:

-Wconversion  
    Warn about implicit conversions that are likely to change the
    value of the expression after conversion. Implied by -Wall.  
 -Wconversion-extra  
    Warn about implicit conversions between different types and
    kinds. This option does not imply -Wconversion.

If I use this latter flag with the following program

  use, intrinsic :: iso_fortran_env, only : real32, real64
  real(real64) x
  x = 1._real32
end

I get exactly (albeit using gfortran 4.8.1) a warning message requested in the question title

Warning: Conversion from REAL(4) to REAL(8) at (1)

whereas with just -Wconversion I get nothing. If I change the program slightly, however, so that the changing of representable values kicks in, I get (different) warnings with each.

ifort, on the other hand (up to 19.0.5), appears to have no comparable warning.



来源:https://stackoverflow.com/questions/32054301/how-can-i-make-gfortran-or-ifort-tell-me-when-it-implicitly-promotes-a-real4-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!