Skip to content

Fix PGI warnings about intent for restart_CS#149

Merged
marshallward merged 2 commits into
NOAA-GFDL:dev/gfdlfrom
adcroft:fix-pgi-intent-warnings
Jul 4, 2022
Merged

Fix PGI warnings about intent for restart_CS#149
marshallward merged 2 commits into
NOAA-GFDL:dev/gfdlfrom
adcroft:fix-pgi-intent-warnings

Conversation

@adcroft
Copy link
Copy Markdown
Member

@adcroft adcroft commented Jun 17, 2022

  • 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 the offending lines that change the state. Apparently we didn't need them!

- 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
Copy link
Copy Markdown

codecov Bot commented Jun 17, 2022

Codecov Report

Merging #149 (0bf3541) into dev/gfdl (d2d3236) will increase coverage by 0.00%.
The diff coverage is n/a.

@@            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     
Impacted Files Coverage Δ
src/framework/MOM_restart.F90 29.24% <ø> (+0.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2d3236...0bf3541. Read the comment docs.

Hallberg-NOAA added a commit to Hallberg-NOAA/MOM6 that referenced this pull request Jun 20, 2022
  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.
Copy link
Copy Markdown
Member

@Hallberg-NOAA Hallberg-NOAA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@marshallward
Copy link
Copy Markdown
Member

Gaea regression: https://gitlab.gfdl.noaa.gov/ogrp/MOM6/-/pipelines/16040 ✔️

@marshallward marshallward merged commit 1e9febe into NOAA-GFDL:dev/gfdl Jul 4, 2022
marshallward pushed a commit that referenced this pull request Jul 5, 2022
  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.
Hallberg-NOAA added a commit to Hallberg-NOAA/MOM6 that referenced this pull request Jul 18, 2022
  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.
marshallward pushed a commit that referenced this pull request Jul 26, 2022
  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.
@adcroft adcroft deleted the fix-pgi-intent-warnings branch June 26, 2023 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants