Skip to content

Commit

Permalink
Merge #555
Browse files Browse the repository at this point in the history
555: Performance patch r=charleskawczynski a=charleskawczynski

This is a peel off PR from #473. This PR adds a few ``@inbounds`` to some loops, and a performance patch for ClimaCore fields. See [ClimaCore.jl's 275](CliMA/ClimaCore.jl#275)

Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
  • Loading branch information
bors[bot] and charleskawczynski committed Nov 10, 2021
2 parents b6fba21 + c41ec7c commit b88f2eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/EDMF_Updrafts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function compute_precipitation_formation_tendencies(
end
end
# TODO - to be deleted once we sum all tendencies elsewhere
for k in real_center_indices(grid)
@inbounds for k in real_center_indices(grid)
aux_bulk.θ_liq_ice_tendency_precip_formation[k] = 0
aux_bulk.qt_tendency_precip_formation[k] = 0
for i in 1:(up.n_updrafts)
@inbounds for i in 1:(up.n_updrafts)
aux_bulk.θ_liq_ice_tendency_precip_formation[k] += aux_up[i].θ_liq_ice_tendency_precip_formation[k]
aux_bulk.qt_tendency_precip_formation[k] += aux_up[i].qt_tendency_precip_formation[k]
end
Expand Down
13 changes: 13 additions & 0 deletions src/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,16 @@ function FieldFromNamedTuple(space, nt::NamedTuple)
cmv(z) = nt
return cmv.(CC.Fields.coordinate_field(space))
end

# https://github.com/CliMA/ClimaCore.jl/issues/275
transform_broadcasted(bc::Base.Broadcast.Broadcasted{CC.Fields.FieldVectorStyle}, symb, axes) =
Base.Broadcast.Broadcasted(bc.f, map(arg -> transform_broadcasted(arg, symb, axes), bc.args), axes)
transform_broadcasted(fv::CC.Fields.FieldVector, symb, axes) = parent(getproperty(fv, symb))
transform_broadcasted(x, symb, axes) = x
@inline function Base.copyto!(dest::CC.Fields.FieldVector, bc::Base.Broadcast.Broadcasted{CC.Fields.FieldVectorStyle})
for symb in propertynames(dest)
p = parent(getproperty(dest, symb))
Base.copyto!(p, transform_broadcasted(bc, symb, axes(p)))
end
return dest
end
2 changes: 1 addition & 1 deletion src/Turbulence_PrognosticTKE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ function GMV_third_m(

if is_tke
parent(ϕ_en_cov) .= 0
for i in 1:N_up
@inbounds for i in 1:N_up
horiz_K_eddy = aux_up_c[i].horiz_K_eddy
a_up = aux_up_c[i].area
a_bulk = aux_bulk.area
Expand Down

0 comments on commit b88f2eb

Please sign in to comment.