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

ccpp_prebuild.py: add support for chunked arrays #519

Merged

Conversation

climbfuji
Copy link
Collaborator

@climbfuji climbfuji commented Dec 27, 2023

Description

Add support for using chunked arrays to ccpp_prebuild.py while maintaining backward compatibility with the use of blocked data structures.

This PR adds support (and a test) for using chunked arrays as an alternative to blocked data structures to ccpp_prebuild.py. The idea behind this is that we can convert the ufs-weather-model to using contiguous arrays that are sent in chunks to the physics for (OpenMP-)parallel processing in the time integration (run) phase. The expectation is that this is at least as fast as the current implementation that uses blocked data structures (because the need to copy non-contiguous arrays into contiguous arrays and back for the init, timestep_init, timestep_finalize and finalize phases is removed). There is also evidence from extensive testing with CESM by CISL that sending chunks of contiguous arrays is faster.

Note. This PR does not yet make any changes for the ufs-weather-model, NEPTUNE or the SCM. It only provides the capability (and a test case that can serve as a how-to) for using contiguous arrays that can be sent to the physics in chunks in the run phase. There are limitations with how we (within ccpp_prebuild) treat inactive (unallocated) host model data that do not allow us to switch over to contiguous arrays immediately. I left several notes in the files changed in this PR to highlight the problems. We need to find a different way to handle inactive data as a next step so that we can make the switch to contiguous arrays afterwards. This will have the positive (!) side effect that it will address concerns raised by NCO that the current approach violates operational requirements.

User interface changes?: No

Issues

Fixes #520

Testing

test removed: none
test added: added test_prebuild/test_chunked_data/*
unit/system tests: all capgen unit/system tests pass (test/run_test.sh); all ccpp_prebuild unit/system tests pass (everything in test_prebuild)
end-to-end tests: full regression tests with ufs-weather-model on Hera with Intel and GNU against existing baseline; all tests pass; see also ufs-community/ufs-weather-model#2066 for final regression testing
manual testing: extensively tested on my macOS with apple-clang+gfortran

Dependencies / associated PRs

This PR is part of a set of PRs that need to be tested and merged together:

scripts/mkstatic.py Outdated Show resolved Hide resolved
array_size = []
dim_substrings = []
for dim in var.dimensions:
# DH* TODO
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs to be addressed in a follow-up PR, because we can't switch the ufs-weather-model and other models using potentially inactive variables to contiguous arrays without fixing the current way we handle them.

scripts/mkstatic.py Outdated Show resolved Hide resolved
f"horizontal dimension for {var_standard_name} is {var.dimensions}")
# *DH

# DH* TODO: WE CANNOT ACTIVATE USING EXPLICIT HORIZONTAL DIMENSIONS
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above, we need to fix the way we handle inactive variables to make the switch to contiguous arrays.

@climbfuji climbfuji marked this pull request as ready for review December 28, 2023 22:31
@climbfuji climbfuji self-assigned this Dec 28, 2023
@climbfuji climbfuji added enhancement ccpp_prebuild bugs, requests, etc. that involve ccpp_prebuild capgen-unification labels Dec 28, 2023
cdata => ccpp_data_chunks(ic)
call ccpp_physics_run(cdata, suite_name=trim(ccpp_suite), ierr=ierr)
if (ierr/=0) then
write(error_unit,'(a,i3,a)') "An error occurred in ccpp_physics_run for block", ic, ":"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should "block" be "chunk" here?

Copy link
Collaborator

@grantfirl grantfirl left a comment

Choose a reason for hiding this comment

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

This looks fine to me from a coding point-of-view. A big question is "what methods of handling 'inactive' variables are correct, or at least consistent, with how this works"? And, by "handling" inactive variables, are you referring to both sides (i.e. host side and scheme side)?

Copy link
Collaborator

@mkavulich mkavulich left a comment

Choose a reason for hiding this comment

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

Looks good to me, just one comment in addition to Grant's review.

test_prebuild/test_chunked_data/main.F90 Outdated Show resolved Hide resolved
Copy link
Collaborator

@gold2718 gold2718 left a comment

Choose a reason for hiding this comment

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

I'm sorry that I do not have time for a really detailed review but I don't see anything troublesome on a quick review (except that I do not really understand how this transition will work with changes to the UFS and did not understand @climbfuji's comment in mkstatic.py).

@climbfuji climbfuji requested a review from peverwhee January 22, 2024 16:34
@mkavulich
Copy link
Collaborator

Waiting for RTs to succeed on ufs-community/ufs-weather-model#2066

@climbfuji
Copy link
Collaborator Author

@dustinswales @grantfirl I think we can move ahead with this PR and the associated ccpp-physics PR. For that one, we wanted to wait for the outcome of our active attribute discussion. Now that we know that we would have to make changes anyway to the ozone physics, we might as well merge this here first (make it compliant with current CCPP rules) and then update ALL of the potentially inactive (= optional) variables in a next round?

@zach1221
Copy link

@climbfuji testing is complete on ufs-wm PR #2066. Are you able to merge this ccpp-physics framework PR?

@climbfuji
Copy link
Collaborator Author

I can merge both but would prefer if @dustinswales or @grantfirl did that

@dustinswales dustinswales merged commit f0b9a18 into NCAR:main Feb 23, 2024
1 check passed
zach1221 pushed a commit to ufs-community/ufs-weather-model that referenced this pull request Feb 23, 2024
…run compile jobs of regression test suite only & -mcmodel=medium gnu.cmake option (also includes #2142) (#2066)

* UFSWM - Add option to `rt.sh` to run compile-only tests
  * FV3 - Update submodule pointer (NOAA-EMC/fv3atm#747)
    * ccpp-physics - Update submodule pointer (ufs-community/ccpp-physics#150)
    * ccpp-framework - Update submodule pointer (NCAR/ccpp-framework#519)
* Update WM license and documentation logo
* Update GNU.cmake: -mcmodel=medium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
capgen-unification ccpp_prebuild bugs, requests, etc. that involve ccpp_prebuild enhancement
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

ccpp_prebuild.py: add capability to use chunks of contiguous arrays in the run phase
6 participants