我如何让 gfortran 或 ifort 告诉我它何时将 RE​​AL(4) 隐式提升为 REAL(8)? [英] How can I make gfortran or ifort tell me when it implicitly promotes a REAL(4) to a REAL(8)?

查看:33
本文介绍了我如何让 gfortran 或 ifort 告诉我它何时将 RE​​AL(4) 隐式提升为 REAL(8)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

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

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

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

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

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

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

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

推荐答案

您指的是使用 gfortran 5.2.0,所以让我们看一下该版本的文档而不是 4.1.0.这有 您认为的两个相关标志:

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

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

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)

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

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(最高 19.0.5)似乎没有类似的警告.

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

这篇关于我如何让 gfortran 或 ifort 告诉我它何时将 RE​​AL(4) 隐式提升为 REAL(8)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆