ISO_FORTRAN_ENV或-fdefault-real-8将实数提升为双精度 [英] ISO_FORTRAN_ENV or -fdefault-real-8 to promote reals to double precision

查看:558
本文介绍了ISO_FORTRAN_ENV或-fdefault-real-8将实数提升为双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用gfortran-fdefault-real-8选项自动将程序中任何地方声明的每个REAL提升为双精度,以及任何常量例如 1.23.如果我想切换回单精度,则只需删除该选项并重新编译,而无需在源代码中更改单个字符.

我开始使用ISO_FORTRAN_ENV模块,因为它允许我使用INPUT|OUTPUT|ERROR_UNIT以及IOSTAT_ENDIOSTAT_EOR等常量(这似乎是一个好而容易的方法).便携性的方向,我错了吗?).从那时起,我一直在看到并忽略以下警告

Warning: Use of the NUMERIC_STORAGE_SIZE named constant from intrinsic module ISO_FORTRAN_ENV at (1) is incompatible with option -fdefault-real-8

因为到目前为止这种不兼容似乎没有效果.

现在,如果可能并且值得的话,我想摆脱这个警告.

如果我正确理解,为避免此警告,我应该放弃-fdefault-real-8选项,并将每个REAL更改为REAL(real64) 和/或 REAL(dp)(前提是,在后一种情况下,将USE, INTRINSIC :: ISO_FORTRAN_ENV, dp => real64语句放置在该单元中),对于sedvim而言,这并不是一项艰巨的任务.

不过,在我看来,此更改与使用-fdefault-real-8选项并不相同,因为只要我不添加d0所有常量都将保持单精度.给他们. 假设已删除 -fdefault-real-8 选项,并且在任何地方都使用了ISO_FORTRAN_ENV,是否有任何方法可以使程序中的任何常量表现为每个都有d0后缀的行为? 不管这是否可行,我是否可以正确地推断出可以将以下行放入一个模块,该模块供所有其他程序单元使用,然后每个程序单元都可以使用dp作为种类类型参数?

USE, INTRINSIC :: ISO_FORTRAN_ENV
INTEGER, PARAMETER :: dp = real64

我更喜欢这种方式,因为我可以通过仅更改该行来切换到real32real128或其他任何内容.

解决方案

如果您只是想使警告静音,并且不关心-fdefault-real-8对存储关联和某些Fortran标准要​​求的影响,请不要导入模块中的NUMERIC_STORAGE_SIZE.例如,

USE, INTRINSIC :: ISO_FORTRAN_ENV, only: INPUT_UNIT,OUTPUT_UNIT,ERROR_UNIT

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.

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.

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.

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 -fdefault-real-8 option is removed and 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

I would prefer this way since I could switch to real32 or real128 or whatever by changing only that line.

解决方案

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屋!

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