Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
655 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...