ISO_FORTRAN_ENV 或 -fdefault-real-8 将实数提升为双精度 [英] ISO_FORTRAN_ENV or -fdefault-real-8 to promote reals to double precision
问题描述
我一直在使用 gfortran
的 -fdefault-real-8
选项来自动提升在程序到双精度,连同任何常数,例如 1.23
.如果我想切换回单精度,我只需要删除该选项并重新编译,而无需更改源代码中的单个字符.
I've always been using the -fdefault-real-8
option of gfortran
to automatically promote every single REAL
declared anywhere in the program to double precision, along with any constant, e.g. 1.23
. If I ever wanted to switch back to single precision, I only had to remove that option and recompile, without changing a single character in the source code.
我开始使用 ISO_FORTRAN_ENV
模块,因为它允许我使用 INPUT|OUTPUT|ERROR_UNIT
等常量,以及 IOSTAT_END
和 IOSTAT_EOR
和其他人(这似乎是朝着可移植性方向发展的一个好而简单的举措,我错了吗?).从那时起,我一直看到并忽略以下警告
At a point I started using ISO_FORTRAN_ENV
module, since it allows me to use constants like INPUT|OUTPUT|ERROR_UNIT
, as well as IOSTAT_END
and IOSTAT_EOR
and others (which seemed to be a good and easy move in the direction of portability, am I wrong?). From then on, I've been seeing and ignoring the following warning
Warning: Use of the NUMERIC_STORAGE_SIZE named constant from intrinsic module ISO_FORTRAN_ENV at (1) is incompatible with option -fdefault-real-8
因为到目前为止这种不兼容似乎没有任何影响.
since such incompatibility seems to have no effect so far.
现在,如果可能且值得的话,我想去掉这个警告.
Now I'd like to get rid of this warning if it is possible and worth it.
如果我理解正确,为避免此警告,我应该放弃 -fdefault-real-8
选项并将每个 REAL
更改为 REAL(real64)
和/或到 REAL(dp)
(前提是,在后者在这种情况下,将语句 USE, INTRINSIC :: ISO_FORTRAN_ENV, dp => real64
放在该单元中),这对于 sed
或 vim 来说并不困难
.
If I correctly understood, to avoid this warning I should give up on -fdefault-real-8
option and change every REAL
to REAL(real64)
and/or to REAL(dp)
(provided that, in the latter case, the statement USE, INTRINSIC :: ISO_FORTRAN_ENV, dp => real64
is put in that unit), which is not a difficult task for sed
or vim
.
不过,在我看来,这种更改与使用 -fdefault-real-8
选项不同,因为 所有常量都将保持单精度只要我不向他们添加 d0
.假设 选项被删除并且 -fdefault-real-8
ISO_FORTRAN_ENV
在任何地方使用,有没有办法让程序中的任何常量表现因为每个都有 d0
后缀?无论这是否可能,我是否正确推断我可以将以下几行放在一个模块中,所有其他程序单元都使用该模块,然后每个模块都可以使用 dp
作为种类类型参数?
Nevertheless, it seems to me that this change wouldn't be the same as using -fdefault-real-8
option, since all constants would stay single precision as long as I don't add d0
to them.
Assumed the option is removed and -fdefault-real-8
ISO_FORTRAN_ENV
is used anywhere, is there any way to make any constant across the program behave as each had d0
suffix?
Whether or not this is possible, have I correctly extrapolated that I can put the following lines in a single module which is used by all others program units, each of which can then use dp
as kind type parameter?
USE, INTRINSIC :: ISO_FORTRAN_ENV
INTEGER, PARAMETER :: dp = real64
我更喜欢这种方式,因为我可以通过仅更改该行来切换到 real32
或 real128
或其他任何方式.
I would prefer this way since I could switch to real32
or real128
or whatever by changing only that line.
推荐答案
如果你只想让警告静音,而不关心 -fdefault-real-8
对存储关联的影响和一些 Fortran 标准要求,只是不要从模块中导入 NUMERIC_STORAGE_SIZE
.例如,
If you just want to silence the warning and you do not care about the implications -fdefault-real-8
has on storage association and some Fortran standard requirements, just do not import NUMERIC_STORAGE_SIZE
from the module. For example,
USE, INTRINSIC :: ISO_FORTRAN_ENV, only: INPUT_UNIT,OUTPUT_UNIT,ERROR_UNIT
这篇关于ISO_FORTRAN_ENV 或 -fdefault-real-8 将实数提升为双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!