Fix PGI warnings about intent for restart_CS#149
Conversation
- The PGI compiler was complaining about some `intent(in) :: CS`
in MOM_restart.F90. This was because of a line that changes the
state of data pointed to from within `CS`, but not `CS` itself:
CS%restart_field(n)%initialized = .true.
The strict interpretation is that `CS` is not modified because
`CS%restart_field` is a pointer to memory elsewhere. However, the
`intent(in)` indicates to the user/programmer that nothing changes
and since all arguments to the functions are `intent(in)` most entities,
including the PGI compiler, should be surprised that something changed
as a result of a passive "query" function. This strict interpretation
allows a devious hidden-change-of-state to occur.
- Changing the intent to `intent(inout)` has the consequence that the
new intent has to be propagated upwards through the code. And why should
a type be `intent(out)` for query functions?
- This commit removes offending lines that change the state. Apparently
we didn't need them!?
Codecov Report
@@ Coverage Diff @@
## dev/gfdl #149 +/- ##
=========================================
Coverage 34.04% 34.05%
=========================================
Files 259 259
Lines 70138 70126 -12
Branches 12996 12984 -12
=========================================
- Hits 23880 23879 -1
+ Misses 41761 41753 -8
+ Partials 4497 4494 -3
Continue to review full report at Codecov.
|
Added the overloaded interface set_initialized() to the MOM_restart module, to record that fields have been initialized, despite not appearing in a restart file. This will allow for a second call to set_initialized() after a call to query_initialized() to replicate the existing behavior of query_initialized() after MOM6 PR mom-ocean#149 (NOAA-GFDL#149) has been accepted. All answers are bitwise identical, but there is a new public interface.
Hallberg-NOAA
left a comment
There was a problem hiding this comment.
I agree with these changes, provided we also consider the complementary pull request PR #152, which will recover the capability that is being eliminated.
I agree that query functions should not have the hidden side effect of modifying anything, but an explicit call to avoid repeating approximate initializations or recording that other dependent calculations can be done is still useful.
|
Gaea regression: https://gitlab.gfdl.noaa.gov/ogrp/MOM6/-/pipelines/16040 ✔️ |
Added the overloaded interface set_initialized() to the MOM_restart module, to record that fields have been initialized, despite not appearing in a restart file. This will allow for a second call to set_initialized() after a call to query_initialized() to replicate the existing behavior of query_initialized() after MOM6 PR #149 (#149) has been accepted. All answers are bitwise identical, but there is a new public interface.
Call set_initialized for variables after they are initialized, when their lack of initialization was detected via query_initialized. This commit reproduces the model's behavior prior to the removal of the code that set the initialized flag within query_initialized in NOAA-GFDL#149, and it completes the set of changes that was envisioned when set_initialized was added in NOAA-GFDL#152. All answers are bitwise identical.
Call set_initialized for variables after they are initialized, when their lack of initialization was detected via query_initialized. This commit reproduces the model's behavior prior to the removal of the code that set the initialized flag within query_initialized in #149, and it completes the set of changes that was envisioned when set_initialized was added in #152. All answers are bitwise identical.
intent(in) :: CSin MOM_restart.F90. This was because of a line that changes the state of data pointed to from withinCS, but notCSitself:CS%restart_field(n)%initialized = .true.. The strict interpretation is thatCSis not modified becauseCS%restart_fieldis a pointer to memory elsewhere. However, theintent(in)indicates to the user/programmer that nothing changes and since all arguments to the functions areintent(in)most entities, including the PGI compiler, should be surprised that something changed as a result of a passive "query" function. This strict interpretation allows a devious(?) hidden-change-of-state to occur.intent(inout)has the consequence that the new intent has to be propagated upwards through the code. And why should a type beintent(out)for query functions?