-
Notifications
You must be signed in to change notification settings - Fork 353
Declare constants at the native precision of MPAS #1282
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
Declare constants at the native precision of MPAS #1282
Conversation
When building MPAS as a dycore, certain constants in the `mpas_constants` module are imported from the `physconst` module, which is a part of CAM/CAM-SIMA. However, multiple issues arise if the precision of those constants differs from MPAS. For example, building MPAS in single precision mode with CAM-SIMA fails due to multiple occurrences of type mismatch between actual and dummy arguments. mpas_geometry_utils.F:885:157: 885 | call mpas_log_write('$r', MPAS_LOG_ERR, realArgs=(/mpas_triangle_signed_area_sphere(a,b,c,sphereRadius) - pii/2.0_RKIND*sphereRadius*sphereRadius/)) | 1 Error: Type mismatch in argument 'realargs' at (1); passed REAL(8) to REAL(4) Here, `pii` is declared by CAM-SIMA to be double precision, and it causes unintended floating-point promotion in the expression. The solution is to ensure that constants in the `mpas_constants` module are declared at the native precision of MPAS.
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.
Overall looks good. I did have a few comments and question though.
0bee41d
to
a0f530b
Compare
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.
Looks good!
@kuanchihwang The code changes themselves look good. However, I'd like to request a few minor changes to the commit messages so that they more specifically describe what is being modified. For example, the commit messages
and
give no indication of what code is affected. Could you revisit the commit messages and ensure that they make it clear what module, file, or part of the model is being affected? I'm not suggesting we add a list of modified files to each commit message, but rather, reference module or file names in the text. For example, the last commit message I mentioned above could become:
|
In the `mpas_constants` module, enforce `implicit none` at the module level so it applies everywhere within. It is also a best practice in Fortran.
…e level of `mpas_constants` A blanket `use` statement imports all public entities from that module. For the case here, it causes namespace pollution at the module level of `mpas_constants`. Also, it is difficult to tell where the imported entities come from. Therefore, `use` statements should always include the `only` option. It is also a best practice in Fortran.
It is a best practice in Fortran to always specify the accessibility of module variables (as well as procedures). For the case here, `RKIND` is imported from `mpas_kind_types`. Due to the lack of accessibility attributes, other modules that `use mpas_constants` also have access to `RKIND`. Therefore, avoid causing unexpected namespace pollution to other modules by specifying explicit accessibility attributes.
Several instances of trailing spaces have been removed, and a blank line has been added above the `contains` statement in the `mpas_constants` module for consistency with other MPAS modules.
a0f530b
to
1353687
Compare
I have amended the commit messages to include more specific information about what they modify. The commit contents remain the same as can be seen by comparison. |
When building MPAS as a dynamical core, certain constants in the
mpas_constants
module are imported from thephysconst
module, which is a part of CAM/CAM-SIMA. However, multiple issues arise if the precision of those constants differs from MPAS.For example, building MPAS in single precision mode with CAM-SIMA fails due to multiple occurrences of type mismatch between actual and dummy arguments.
Here,
pii
is declared by CAM-SIMA to be double precision, and it causes unintended floating-point promotion in the expression.The solution is to ensure that constants in the
mpas_constants
module are declared at the native precision of MPAS. Note that CAM does not support running MPAS in single precision mode at all, so the above build error cannot be reproduced.In addition, some best practices of modern Fortran have been implemented.
For stand-alone MPAS, the compiled executables stay bitwise identical, with or without this PR. No further tests are needed. For CAM/CAM-SIMA, it generates bitwise identical model results, with or without this PR. Additionally for CAM-SIMA, its regression tests all pass, indicating identical model results to the previous baseline.