Skip to content

Commit 43410b9

Browse files
committed
Improve tracer performance in jacobian update
Split up a high register pressure broadcast. It appears that just the broadcast is nearly seven times as fast after the change. SYPD for 1m with 30 he improves by ~11%
1 parent 576ac23 commit 43410b9

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/cache/temporary_quantities.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ClimaCore: Fields
22
using ClimaCore.Utilities: half
3+
using ClimaCore.MatrixFields
34

45
# Fields used to store variables that only need to be used in a single function
56
# but cannot be computed on the fly. Unlike the precomputed quantities, these
@@ -62,6 +63,11 @@ function temporary_quantities(Y, atmos)
6263
NTuple{n_mass_flux_subdomains(atmos.turbconv_model), CT12{FT}},
6364
face_space,
6465
), # ᶠω¹²ʲs
66+
# TODO: better names for theis scratch fields
67+
ᶜbidiagonal_adjoint_matrix_c3 = Fields.Field(
68+
BidiagonalMatrixRow{Adjoint{FT, C3{FT}}},
69+
center_space,
70+
),
6571
ᶠtemp_C123 = Fields.Field(C123{FT}, face_space), # χ₁₂₃
6672
ᶜtemp_UVW = Fields.Field(typeof(uvw_vec), center_space), # UVW(ᶜu)
6773
ᶠtemp_UVW = Fields.Field(typeof(uvw_vec), face_space), # UVW(ᶠu³)
@@ -76,6 +82,15 @@ function temporary_quantities(Y, atmos)
7682
∂ᶜK_∂ᶠu₃ = similar(Y.c, BidiagonalMatrixRow{Adjoint{FT, CT3{FT}}}),
7783
ᶠp_grad_matrix = similar(Y.f, BidiagonalMatrixRow{C3{FT}}),
7884
ᶠbidiagonal_matrix_ct3 = similar(Y.f, BidiagonalMatrixRow{CT3{FT}}),
85+
# TODO: better names for theis scratch fields
86+
ᶠband_matrix_wvec = similar(
87+
Y.f,
88+
ClimaCore.MatrixFields.BandMatrixRow{
89+
ClimaCore.Utilities.PlusHalf{Int64}(0),
90+
1,
91+
ClimaCore.Geometry.WVector{FT},
92+
},
93+
),
7994
ᶠbidiagonal_matrix_ct3_2 = similar(Y.f, BidiagonalMatrixRow{CT3{FT}}),
8095
ᶜadvection_matrix = similar(
8196
Y.c,

src/prognostic_equations/implicit/manual_sparse_jacobian.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,16 +565,21 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
565565
# p.precomputed.ᶜwₜqₜ / ᶜq_tot,
566566
# ),
567567
# ) - (I,)
568-
569568
MatrixFields.unrolled_foreach(tracer_info) do (ρχₚ_name, wₚ_name)
570569
MatrixFields.has_field(Y, ρχₚ_name) || return
571570
∂ᶜρχₚ_err_∂ᶜρχₚ = matrix[ρχₚ_name, ρχₚ_name]
572571
ᶜwₚ = MatrixFields.get_field(p.precomputed, wₚ_name)
572+
# TODO: Maybe just reinterpret an existing scratch field to avoid adding 2 new ones
573+
# TODO: come up with read-able names for the intermediate computations...
574+
@. p.scratch.ᶜbidiagonal_adjoint_matrix_c3 =
575+
-(ClimaAtmos.ᶜprecipdivᵥ_matrix())
576+
DiagonalMatrixRow(ClimaAtmos.ᶠinterp(ᶜρ * ᶜJ) / ᶠJ)
577+
@. p.scratch.ᶠband_matrix_wvec =
578+
ClimaAtmos.ᶠright_bias_matrix()
579+
DiagonalMatrixRow(ClimaCore.Geometry.WVector(-(ᶜwₚ) / ᶜρ))
573580
@. ∂ᶜρχₚ_err_∂ᶜρχₚ =
574-
dtγ * -(ᶜprecipdivᵥ_matrix())
575-
DiagonalMatrixRow(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ)
576-
ᶠright_bias_matrix()
577-
DiagonalMatrixRow(-Geometry.WVector(ᶜwₚ) / ᶜρ) - (I,)
581+
dtγ * p.scratch.ᶜbidiagonal_adjoint_matrix_c3
582+
p.scratch.ᶠband_matrix_wvec - (I,)
578583
end
579584

580585
end

0 commit comments

Comments
 (0)