Skip to content
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

Extend diag_mediator to allow the piecemeal posting of diagnostics #809

Open
wants to merge 7 commits into
base: dev/gfdl
Choose a base branch
from

Conversation

ashao
Copy link

@ashao ashao commented Jan 20, 2025

Some quantities in MOM6 are calculated in subroutines which expect slices of the model's 2d or 3d arrays. Diagnosing these quantities can be challenging because the usual post_data calls expect whole arrays. To solve this problem, the changes here introduce a dynamic buffer that can grow as needed over the course of an simulation.

This buffer keeps track of the diagnostic IDs and the index in the buffer. When a slot in the buffer is no longer needed, for example if the whole array has been computed and posted, the slot is marked as "available" for overwriting. The buffer is only allowed to grow if all the currently allocated slots are in use.

Any computational cost associated with growing this buffer will only happen in the first few steps of the model as post_data for requested diagnostics is called for the first time in that run.

This new piecemeal posting of a diagnostic was implemented for Kd_ePBL. The new diagnostic Kd_ePBL_col_by_col is the same as the the original field in the Baltic_OM4_05 case.

@adcroft @marshallward: Two points in particular that I'd like your feedback on:

  • The underlying buffer is public, but I cannot think of a way to make it private and still allow a post_data call to be done without an extra copy. I have included a store subroutine that could be used if we made it private, but otherwise those should be deleted.
  • Each time we post the data in a piecemeal fashion, the slot index is computed. We could put in some logic so that we store it once per loop at the beginning of the section where the diagnostic is being computed/posted. I am not sure that it would be worth the effort/complexity for what I am assuming would be a marginal performance gain.

ashao added 3 commits January 19, 2025 10:12
Some quantities in MOM6 are calculated in subroutines which expect
slices of the model's 2d or 3d arrays. Diagnosing these quantities
can be challenging because the usual post_data calls expect
whole arrays. To solve this problem, the changes here introduce
a dynamic buffer that can grow as needed over the course of an
simulation.

This buffer keeps track of the diagnostic IDs and the index in
the buffer. When a slot in the buffer is no longer needed, for
example if the whole array has been computed and posted, the
slot is marked as "available" for overwriting. The buffer is only
allowed to grow if all the currently allocated slots are in use.

Any computational cost associated with growing this buffer will
only happen in the first few steps of the model as post_data
for requested diagnostics is called for the first time in that
run.
The diag mediator has been extended to add a dynamic buffer to
each axes group. Three new methods have also been added to enable
the piecemeal posting (by column, by point) of a diagnostic and a
'final' method to allow the buffer to be reused later.
ePBL calculates the vertical diffusivity column by column. This
provides a convenient sanity check of the new piecemeal posting
of diagnostics. The original diagnostic Kd_ePBL is done by posting
the full 3d prognostic array, whereas a new diagnostic
Kd_ePBL_col_by_col posts the same array from within ePBL but does
so column by column.
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

Attention: Patch coverage is 0% with 200 lines in your changes missing coverage. Please review.

Please upload report for BASE (dev/gfdl@40a59f7). Learn more about missing BASE report.
Report is 2 commits behind head on dev/gfdl.

Files with missing lines Patch % Lines
src/framework/MOM_diag_buffers.F90 0.00% 181 Missing ⚠️
src/framework/MOM_diag_mediator.F90 0.00% 19 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             dev/gfdl     #809   +/-   ##
===========================================
  Coverage            ?   21.81%           
===========================================
  Files               ?      137           
  Lines               ?    33019           
  Branches            ?     5850           
===========================================
  Hits                ?     7202           
  Misses              ?    25260           
  Partials            ?      557           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Fixes failures in the CI due to some procedures and type members
not having docstrings.
class(diag_buffer_2d), intent(inout) :: this !< This 2d buffer

integer :: n
real, allocatable, dimension(:,:,:) :: temp
Copy link
Member

@Hallberg-NOAA Hallberg-NOAA Jan 23, 2025

Choose a reason for hiding this comment

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

Please add comments describing the purpose and units of this real variable. (Perhaps the units are [arbitrary] or '[A ~> a]if it might be rescaled later using the contents of aconversionargument to aregister_diag_field()` call.)

The same comment applies to lines 47, 165, 179, 193, 258, 281, 368 and 390.

Copy link
Author

Choose a reason for hiding this comment

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

Comments have been added to indicate that these temporary arrays and the primary buffer in the type are arbitrary. The values (and their accordant units) assigned to these buffers will depend on their actual use within the codebase. Whether these represent scaled arbitrary units, depends on how they are filled from within the codebase. As you point out, in the case of their use as part of post_data, this may be the case, but may not in general hold.

Copy link
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 think that this capability should be extended to include the ability to initialize a diagnostic buffer to land values to avoid the need to call the piecemeal posting for all columns, even over land.

Also, this PR should be revised to adhere to the guidance in the MOM6 style guide at https://github.com/NOAA-GFDL/MOM6/wiki/Code-style-guide, as described in specific comments.

@ashao ashao requested a review from Hallberg-NOAA January 23, 2025 19:02
@ashao
Copy link
Author

ashao commented Jan 23, 2025

@Hallberg-NOAA Thank you for the comments. I have added descriptions of the units (see the inline response) and made the if-statements conform the to the style guide. Additionally, the fill value for the arrays can now be specified; for the purposes of the piecemeal posting of the diagnostics these are set to the DIAG_MISSING_VALUE specified in MOM_input.

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.

2 participants