Skip to content

Remove 3D var_mix copy and use 2D j-slab H3 in vertical_diffusion_2/s - #2483

Open
g8j39 wants to merge 2 commits into
wrf-model:developfrom
g8j39:perf/vdiff2-jslab-cleanup
Open

g8j39 wants to merge 2 commits into
wrf-model:developfrom
g8j39:perf/vdiff2-jslab-cleanup

Conversation

@g8j39

@g8j39 g8j39 commented Nov 17, 2026

Copy link
Copy Markdown

Remove 3D var_mix copy and use 2D j-slab H3 in vertical_diffusion_2/s.

TYPE: enhancement

KEYWORDS: dyn_em, vertical_diffusion_2, vertical_diffusion_s, LES, stack memory

SOURCE: Yoel Sevi (Google)

DESCRIPTION OF CHANGES:
Problem:
vertical_diffusion_2 in dyn_em/module_diffusion_em.F allocates a patch-sized 3D
automatic array var_mix(ims:ime, kms:kme, jms:jme) and copies 3D thp and every
active moisture species moist(:,:,:,im) into var_mix before calling
vertical_diffusion_s. Inside vertical_diffusion_s, four full-tile 3D automatic
arrays (H3, xkxavg, unused rravg, and tmptendf) are allocated and swept across
separate 3D DO j passes even though vertical flux divergence has no j
dependencies.

Solution:

  • Eliminate 3D var_mix in vertical_diffusion_2 by passing thp and
    moist(ims,kms,jms,im) directly to vertical_diffusion_s with an optional 1D
    var_base (t_base or qv_base when .not. mix_full_fields).
  • Drop unused rravg and replace H3, xkxavg, and tmptendf in
    vertical_diffusion_s with a 2D H3(its:ite, kts:kte) j-slab and scalar
    xkxavg_s/tmptendf_s under one fused DO j = j_start, j_end loop with identical
    floating-point evaluation order (net -36 code lines).

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_diffusion_em.F

TESTS CONDUCTED:

  1. Net cleanup removing a patch-sized 3D copy per scalar and four 3D tile
    scratch arrays (runtime impact together with PR 13 (Remove nine 3D scratch arrays and dead loops in tke_dissip and tke_shear #2482) is +0.1 percentage points
    paired on the 3D TKE LES case). vertical_diffusion_2 is not covered by the
    standalone harness; verification is full-model: diffwrf = 0 on the 100-m
    3D TKE LES case (dmpar, plus a smaller dm+sm case), and on em_quarter_ss
    (mix_full_fields = .true.) and a -r8 LES run on an earlier revision of the
    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: Eliminate 3D var_mix copies in vertical_diffusion_2 and replace 3D scratch arrays in vertical_diffusion_s with a 2D H3(its:ite, kts:kte) j-slab (dyn_em/module_diffusion_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, vertical_diffusion_2, vertical_diffusion_s, LES, stack memory

SOURCE: Yoel Sevi (Google)

DESCRIPTION OF CHANGES:
Problem:
vertical_diffusion_2 in dyn_em/module_diffusion_em.F allocates a patch-sized 3D
automatic array var_mix(ims:ime, kms:kme, jms:jme) and copies 3D thp and every
active moisture species moist(:,:,:,im) into var_mix before calling
vertical_diffusion_s. Inside vertical_diffusion_s, four full-tile 3D automatic
arrays (H3, xkxavg, unused rravg, and tmptendf) are allocated and swept across
separate 3D DO j passes even though vertical flux divergence has no j
dependencies.

Solution:
- Eliminate 3D var_mix in vertical_diffusion_2 by passing thp and
  moist(ims,kms,jms,im) directly to vertical_diffusion_s with an optional 1D
  var_base (t_base or qv_base when .not. mix_full_fields).
- Drop unused rravg and replace H3, xkxavg, and tmptendf in
  vertical_diffusion_s with a 2D H3(its:ite, kts:kte) j-slab and scalar
  xkxavg_s/tmptendf_s under one fused DO j = j_start, j_end loop with identical
  floating-point evaluation order (net -36 code lines).

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_diffusion_em.F

TESTS CONDUCTED:
1. Net cleanup removing a patch-sized 3D copy per scalar and four 3D tile
   scratch arrays (runtime impact together with PR 13 is +0.1 percentage points
   paired on the 3D TKE LES case). vertical_diffusion_2 is not covered by the
   standalone harness; verification is full-model: diffwrf = 0 on the 100-m
   3D TKE LES case (dmpar, plus a smaller dm+sm case), and on em_quarter_ss
   (mix_full_fields = .true.) and a -r8 LES run on an earlier revision of the
   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: Eliminate 3D var_mix copies in vertical_diffusion_2 and replace 3D scratch arrays in vertical_diffusion_s with a 2D H3(its:ite, kts:kte) j-slab (dyn_em/module_diffusion_em.F).
@weiwangncar

weiwangncar commented Nov 19, 2026 •

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