Skip to content

Commit

Permalink
Avoid allocations due to usage of broadcasting operation (#1656)
Browse files Browse the repository at this point in the history
* Avoid allocations due to usage of broadcasting operation

* Comments & correcting copy-paste error

---------

Co-authored-by: Hendrik Ranocha <[email protected]>
  • Loading branch information
DanielDoehring and ranocha authored Oct 5, 2023
1 parent adce486 commit 67ddfbb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/solvers/dgmulti/dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,12 @@ function calc_volume_integral!(du, u, mesh::DGMultiMesh,
@threaded for e in eachelement(mesh, dg, cache)
flux_values = local_values_threaded[Threads.threadid()]
for i in eachdim(mesh)
flux_values .= flux.(view(u_values, :, e), i, equations)
# Here, the broadcasting operation does allocate
#flux_values .= flux.(view(u_values, :, e), i, equations)
# Use loop instead
for j in eachindex(flux_values)
flux_values[j] = flux(u_values[j, e], i, equations)
end
for j in eachdim(mesh)
apply_to_each_field(mul_by_accum!(weak_differentiation_matrices[j],
dxidxhatj[i, j][1, e]),
Expand All @@ -327,6 +332,7 @@ function calc_volume_integral!(du, u, mesh::DGMultiMesh{NDIMS, <:NonAffine},
@threaded for e in eachelement(mesh, dg, cache)
flux_values = cache.flux_threaded[Threads.threadid()]
for i in eachdim(mesh)
# Here, the broadcasting operation does not allocate
flux_values[i] .= flux.(view(u_values, :, e), i, equations)
end

Expand Down

0 comments on commit 67ddfbb

Please sign in to comment.