How can I make gfortran or ifort tell me when it i

2019-08-06 08:57发布

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条回答
贪生不怕死
2楼-- · 2019-08-06 09:19

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.

查看更多
登录 后发表回答