当 gfortran 或 ifort 隐含地将 REAL(4) 提升为 REAL(8) 时,我如何才能告诉我?

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

我的任务是更改 HPC 应用程序部分的精度,请记住它严重依赖自动矢量化。因此,编译器在发生任何类型的浮点转换时通知我很有用(因为这可能会对性能产生严重影响)。

-Wconversion 标志听起来应该适合我的需要:

-Wconversion

Warn about implicit conversions between different types.


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

然而,实际上,gfortran 5.2.0 似乎只报告浮点降级,例如 REAL(8)REAL(4)

GCC 有 -Wdouble-promotion 标志——正是我需要的,但不适用于 gfortran。 (https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html)

我正在使用 gfortran 进行开发,但我可以使用 ifort。但是,我找不到 -warn (https://software.intel.com/en-us/node/525184) 的任何类似参数。

如何让这些编译器在隐式提升 REAL 时发出警告?

您指的是使用 gfortran 5.2.0,所以让我们看看该版本而不是 4.1.0 的文档。这有 two relevant flags 你认为的:

-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.

如果我在下面的程序中使用后一个标志

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

我准确地(尽管使用 gfortran 4.8.1)得到了问题标题中要求的警告消息

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

而只有 -Wconversion 我什么也得不到。但是,如果我稍微更改程序,以便开始更改可表示值,我会收到每个(不同的)警告。

ifort,另一方面(最高 19.0.5),似乎没有类似的警告。