Skip to content

Carry vertical pressure-flux terms across k and fuse sweeps in advance_w - #2485

Open
g8j39 wants to merge 2 commits into
wrf-model:developfrom
g8j39:perf/small-step-advance-w
Open

g8j39 wants to merge 2 commits into
wrf-model:developfrom
g8j39:perf/small-step-advance-w

Conversation

@g8j39

@g8j39 g8j39 commented Nov 17, 2026

Copy link
Copy Markdown

Carry vertical pressure-flux terms across k and fuse sweeps in advance_w.

TYPE: enhancement

KEYWORDS: dyn_em, advance_w, tridiagonal solver, acoustic small step, module_small_step_em

SOURCE: Yoel Sevi (Google)

DESCRIPTION OF CHANGES:
Problem:
advance_w in dyn_em/module_small_step_em.F runs on every acoustic substep (7
calls per RK3 step with 4 sound steps, 10 with 6). At every vertical level k,
it recomputes the lower-interface pressure-flux division
c2a(i,k-1,j)*rdnw(k-1)/(c1h(k-1)*MUT+c2h(k-1)) and geopotential difference
dphi_km1 already computed at level k-1, and sweeps separate k-loops for
t_2ave/rhs/wdwn setup, forward tridiagonal elimination, and backward ph update.

Solution:

  • Fuse the t_2ave/rhs/wdwn setup pass and hoist top_lid outside the k-loop.
  • Carry 1D q_dp(its:ite) and dphi_km1(its:ite) from level k-1 to k, halving
    floating-point divisions in the vertical w RHS loop.
  • Fuse forward tridiagonal elimination into that k-pass, and fuse backward w
    substitution with the ph update when damp_opt /= 3.

License: Notwithstanding anything else to the contrary set out in https://github.com/wrf-model/WRF, the material here is being released under the Apache 2.0 licence at https://www.apache.org/licenses/LICENSE-2.0 (see doc/licenses/google_license.txt).

LIST OF MODIFIED FILES:
A doc/licenses/google_license.txt
M dyn_em/module_small_step_em.F

TESTS CONDUCTED:

  1. On gfortran 15.2.0 (x86-64 Linux, 4-core VMs, MPICH), passed -fcheck=all and
    sNaN FPE-trap tests (r4 and -r8) across phi_adv_z = 1/2, top_lid T/F, and
    damp_opt = 0/3 with max_abs_diff = 0.0. An earlier broader small-step patch
    saved ~2.3% paired solver time on the 600-step 3D TKE LES case; this trimmed
    patch was not timed in isolation and was verified end-to-end as part of the
    full series.
    Built and verified as part of the full optimization series on x86-64 Linux
    (gfortran 15.2.0, MPICH, 4-core VMs, 5 interleaved repeats across 5 em_real
    workflows) across Make (serial, dmpar r4 and -r8, dm+sm), CMake (dmpar),
    and -DWRF_CHEM=1 with 0 new compiler warnings and bit-for-bit identical
    wrf.exe outputs (diffwrf = 0 with gfortran on x86-64 without fused
    multiply-add).
  2. Pending upstream Jenkins CI (including Intel and non-x86 compilers).

RELEASE NOTE: Carry vertical pressure-flux terms across k and fuse tridiagonal sweeps in advance_w (dyn_em/module_small_step_em.F).

Part of the modular CPU performance series; combined multi-workflow benchmarks, hardware/compiler setup, and per-PR summary table are in the Series Overview comment on PR 01 (#2470).

Prepared with AI assistance (Google Gemini).

TYPE: text only

KEYWORDS: license, Apache-2.0, contributor license, doc/licenses

SOURCE: Yoel Sevi (Google)

DESCRIPTION OF CHANGES:
Problem:
Following the contributor-license mechanism established in PR wrf-model#2242
(doc/licenses/fraunhofer_license.txt), Google-authored code blocks in
subsequent performance pull requests need a standalone permissive license file
under doc/licenses/ while leaving WRF's root LICENSE.txt unmodified.

Solution:
Add doc/licenses/google_license.txt containing the Apache License, Version 2.0
(Copyright 2026 Google LLC), referenced by
`! THE FOLLOWING LINES OF CODE ARE LICENSED UNDER doc/licenses/google_license.txt`
and `! END LICENSE` comment markers around Google-authored code blocks. If
maintainers prefer lower inline marker density on PRs with interleaved edits,
I am happy to explore a lighter per-routine notice option.

License: Notwithstanding anything else to the contrary set out in https://github.com/wrf-model/WRF, the material here is being released under the Apache 2.0 licence at https://www.apache.org/licenses/LICENSE-2.0 (see doc/licenses/google_license.txt).

ISSUE:
None

LIST OF MODIFIED FILES:
A       doc/licenses/google_license.txt

TESTS CONDUCTED:
1. Documentation-only addition under doc/licenses/; zero source, build, or
   runtime changes.
2. Pending upstream Jenkins CI.

RELEASE NOTE: Add doc/licenses/google_license.txt (Apache-2.0) for Google-contributed performance patches.
TYPE: enhancement

KEYWORDS: dyn_em, advance_w, tridiagonal solver, acoustic small step, module_small_step_em

SOURCE: Yoel Sevi (Google)

DESCRIPTION OF CHANGES:
Problem:
advance_w in dyn_em/module_small_step_em.F runs on every acoustic substep (7
calls per RK3 step with 4 sound steps, 10 with 6). At every vertical level k,
it recomputes the lower-interface pressure-flux division
c2a(i,k-1,j)*rdnw(k-1)/(c1h(k-1)*MUT+c2h(k-1)) and geopotential difference
dphi_km1 already computed at level k-1, and sweeps separate k-loops for
t_2ave/rhs/wdwn setup, forward tridiagonal elimination, and backward ph update.

Solution:
- Fuse the t_2ave/rhs/wdwn setup pass and hoist top_lid outside the k-loop.
- Carry 1D q_dp(its:ite) and dphi_km1(its:ite) from level k-1 to k, halving
  floating-point divisions in the vertical w RHS loop.
- Fuse forward tridiagonal elimination into that k-pass, and fuse backward w
  substitution with the ph update when damp_opt /= 3.

License: Notwithstanding anything else to the contrary set out in https://github.com/wrf-model/WRF, the material here is being released under the Apache 2.0 licence at https://www.apache.org/licenses/LICENSE-2.0 (see doc/licenses/google_license.txt).

ISSUE:
None

LIST OF MODIFIED FILES:
M       dyn_em/module_small_step_em.F

TESTS CONDUCTED:
1. On gfortran 15.2.0 (x86-64 Linux, 4-core VMs, MPICH), passed -fcheck=all and
   sNaN FPE-trap tests (r4 and -r8) across phi_adv_z = 1/2, top_lid T/F, and
   damp_opt = 0/3 with max_abs_diff = 0.0. An earlier broader small-step patch
   saved ~2.3% paired solver time on the 600-step 3D TKE LES case; this trimmed
   patch was not timed in isolation and was verified end-to-end as part of the
   full series.
   Built and verified as part of the full optimization series on x86-64 Linux
   (gfortran 15.2.0, MPICH, 4-core VMs, 5 interleaved repeats across 5 em_real
   workflows) across Make (serial, dmpar r4 and -r8, dm+sm), CMake (dmpar),
   and -DWRF_CHEM=1 with 0 new compiler warnings and bit-for-bit identical
   wrf.exe outputs (diffwrf = 0 with gfortran on x86-64 without fused
   multiply-add).
2. Pending upstream Jenkins CI (including Intel and non-x86 compilers).

RELEASE NOTE: Carry vertical pressure-flux terms across k and fuse tridiagonal sweeps in advance_w (dyn_em/module_small_step_em.F).
@weiwangncar

Copy link
Copy Markdown
Collaborator

The regression test results:

Test Type              | Expected  | Received |  Failed
= = = = = = = = = = = = = = = = = = = = = = = =  = = = =
Number of Tests        : 23           24
Number of Builds       : 60           57
Number of Simulations  : 158           150        0
Number of Comparisons  : 95           86        0

Failed Simulations are: 
None
Which comparisons are not bit-for-bit: 
None

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