如何让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应用程序部件的精度,同时铭记它严重依赖于自动矢量化。因此,编译器告诉我何时发生任何类型的浮点转换转换(因为这可能会对性能造成严重影响)。
<$ c
$ b
Wconversion
-Wconversion
标志听起来像它应该适合我的需要:
警告不同类型之间的隐式转换。
https://gcc.gnu.org/onlinedocs/gcc-4.1.0/gfortran/Warning-Options.html
然而,实际上,gfortran 5.2.0似乎只报告浮点降级,例如 REAL(8) 到
REAL(4)
。
GCC的 -Wouble-promotion
标志 - 正是我需要的,但不适用于gfortran。 ( https://gcc.gnu.org/onlinedocs/gcc/Warning-Options。 html )
我正在使用gfortran进行开发,但ifort可用于我。然而,我找不到任何类似的参数 -warn
( https://software.intel.com/zh-cn/node/525184 )。
我怎样才能得到这些编译器在隐式提升REAL时发出警告?解析方案
您可以参考使用gfortran 5.2.0,所以让我们来看看该版本的文档而不是4.1.0。这有两个相关的标志:
-Wconversion
关于隐式转换的警告转换后很可能会改变表达式的值。隐含的-Wall。
-Wconversion-extra
警告不同类型和种类之间的隐式转换。这个选项并不意味着-Wconversion。
如果我在后面的程序中使用后面的标志
use,intrinsic :: iso_fortran_env,only:real32,real64
real(real64)x
x = 1._real32
end
我在问题标题
中准确地(但使用gfortran 4.8.1) (b)$ b
$ b而只是
-Wconversion
我什么都没有。但是,如果我稍微改变了程序,那么为了改变可表示的值,我得到了不同的警告。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)
toREAL(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?
解决方案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.这篇关于如何让gfortran或ifort告诉我何时隐含地将REAL(4)推广到REAL(8)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!