-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistent double precision definitions #2099
Open
islas
wants to merge
22
commits into
wrf-model:release-v4.6.1
Choose a base branch
from
islas:double_precision_define
base: release-v4.6.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…applied globablly
… DOUBLE_PRECISION
The regression test results:
|
amstokely
approved these changes
Sep 23, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these changes look good to me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TYPE: bug fix
KEYWORDS: double precision, configuration, make, cmake
SOURCE: internal
DESCRIPTION OF CHANGES:
Problem:
Currently, the source code has multiple preprocessor definitions for controlling double precision usage (1). Likewise, there are multiple parameter definitions in the IO code for the
WRF_REAL
value (2).Examples of (1) :
Because there is no definitive define for querying double precision, it has been left as an exercise to the contributor to formulate an adequate conditional. While the above and other such forms work, they are not consistent and can be confusing as to the intent.
Examples of (2) in a directory with option
-r8
:Across many different preprocessed files, there appears to be two values of
WRF_REAL
which could lead to undesired behavior when interfacing between different sections of code. This issue arises from thesed
command inexternal/ioapi_share/makefile
wherewrf_io_flags.h
is changed in theinc/
folder only, and thus anything includingexternal/ioapi_share
first has one definition whilst anything includinginc/
has the changed value.While (2) may seem like an entirely separate problem from (1) they are interrelated.
wrf_io_flags.h
already partially contains the necessary logic to control whether to use104
or105
when double precision promotion is requested. The current logic is not being used correctly fully as it uses a totally different (and undefined) form of double precision query :The end result will always be
WRF_FLOAT = WRF_REAL
regardless of-r8
option sincePROMOTE_FLOAT
is not defined anywhere in the configuration / compilation logic. However,WRF_FLOAT
happens to be used correctly since thesed
rewrite has changedWRF_REAL
to105
(effectively the same asWRF_FLOAT = WRF_DOUBLE
). This only works becauseWRF_FLOAT
is exclusively used only in files that access theinc/wrf_io_flags.h
rewritten file and not theexternal/ioapi_share/wrf_io_flags.h
one. Furthermore, aside fromio_int.F
, no code that contains the105
value utilizesWRF_REAL
Solution:
To reduce the overall complexity of various define constructs and IO inconsistencies a singular define
DOUBLE_PRECISION
can be introduced specifically meant to inform sections of code whether double precision promotion has been requested.Adding "one more define" may not sound appealing at first, but it does carry some benefits :
Firstly, it does not require the user to hard code values of
4
or8
for single or double precision, respectively, where those are already defined byNATIVE_RWORDSIZE
andDWORDSIZE
.Furthermore, rather than use
#if (RWORDSIZE == DWORDSIZE)
logic can be simplified to a more coherent statement of#ifdef DOUBLE_PRECISION
which is more readable and better understood in intent.Finally, reducing duplication of defines to do the same thing is good practice and limiting defines to control one thing only avoiding co-opting for multiple roles is also good practice. The first part sounds counter to a new define but
RWORDSIZE
andDOUBLE_PRECISION
serve two different functions - the former to tell us the numeric size of real data in bytes and the latter to tell us if alternate logic should be used. An alternative solution to only use a single define would be to haveDOUBLE_PRECISION
control anrkind
settingRWORDSIZE
much likekind_phys
for ccppFor areas where
WRF_REAL
was used with a value of105
when-r8
is used (io_int.F
), to maintain previous behavior the value should be changed toWRF_FLOAT
. Instead of usingsed
to rewrite the file,#ifdef PROMOTE_FLOAT
will use the validDOUBLE_PRECISION
define to switch control ofWRF_FLOAT
toWRF_DOUBLE
if defined, orWRF_REAL
if not.For the CMake build,
DOUBLE_PRECISION
needs to be added to the defines. No other changes necessary.To reduce the complexity of these changes,
wrf_io_flags.h
is still copied out toinc/
, this may be addressed separately.TESTS CONDUCTED: