Skip to content

Commit

Permalink
Reduce weird allocation when using thread parallelization
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Nov 13, 2023
1 parent ba2c20b commit d854c50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/solvers/dgsem_tree/dg_2d_subcell_limiters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,10 @@ end
var_min = variable_bounds[Symbol(v_string, "_min")]
var_max = variable_bounds[Symbol(v_string, "_max")]
@threaded for element in eachelement(dg, cache)
var_min[:, :, element] .= typemax(eltype(var_min))
var_max[:, :, element] .= typemin(eltype(var_max))
for j in eachnode(dg), i in eachnode(dg)
var_min[i, j, element] = typemax(eltype(var_min))
var_max[i, j, element] = typemin(eltype(var_max))
end
for j in eachnode(dg), i in eachnode(dg)
var_min[i, j, element] = min(var_min[i, j, element],
u[v, i, j, element])
Expand Down Expand Up @@ -904,7 +906,9 @@ end
if limiter.spec_entropy
s_min = variable_bounds[:spec_entropy_min]
@threaded for element in eachelement(dg, cache)
s_min[:, :, element] .= typemax(eltype(s_min))
for j in eachnode(dg), i in eachnode(dg)
s_min[i, j, element] = typemax(eltype(s_min))
end
for j in eachnode(dg), i in eachnode(dg)
s = entropy_spec(get_node_vars(u, equations, dg, i, j, element),
equations)
Expand Down Expand Up @@ -933,7 +937,9 @@ end
if limiter.math_entropy
s_max = variable_bounds[:math_entropy_max]
@threaded for element in eachelement(dg, cache)
s_max[:, :, element] .= typemin(eltype(s_max))
for j in eachnode(dg), i in eachnode(dg)
s_max[i, j, element] = typemin(eltype(s_max))
end
for j in eachnode(dg), i in eachnode(dg)
s = entropy_math(get_node_vars(u, equations, dg, i, j, element),
equations)
Expand Down
20 changes: 13 additions & 7 deletions src/solvers/dgsem_tree/subcell_limiters_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ function (limiter::SubcellLimiterIDP)(u::AbstractArray{<:Any, 4}, semi, dg::DGSE
for j in 2:nnodes(dg), i in eachnode(dg)
alpha2[i, j, element] = max(alpha[i, j - 1, element], alpha[i, j, element])
end
alpha1[1, :, element] .= zero(eltype(alpha1))
alpha1[nnodes(dg) + 1, :, element] .= zero(eltype(alpha1))
alpha2[:, 1, element] .= zero(eltype(alpha2))
alpha2[:, nnodes(dg) + 1, element] .= zero(eltype(alpha2))
for i in eachnode(dg)
alpha1[1, i, element] = zero(eltype(alpha1))
alpha1[nnodes(dg) + 1, i, element] = zero(eltype(alpha1))
alpha2[i, 1, element] = zero(eltype(alpha2))
alpha2[i, nnodes(dg) + 1, element] = zero(eltype(alpha2))
end
end

return nothing
Expand All @@ -88,8 +90,10 @@ end
mesh, equations, dg, cache = mesh_equations_solver_cache(semi)
# Calc bounds inside elements
@threaded for element in eachelement(dg, cache)
var_min[:, :, element] .= typemax(eltype(var_min))
var_max[:, :, element] .= typemin(eltype(var_max))
for j in eachnode(dg), i in eachnode(dg)
var_min[i, j, element] = typemax(eltype(var_min))
var_max[i, j, element] = typemin(eltype(var_max))
end
# Calculate bounds at Gauss-Lobatto nodes using u
for j in eachnode(dg), i in eachnode(dg)
var = u[variable, i, j, element]
Expand Down Expand Up @@ -189,7 +193,9 @@ end
mesh, equations, dg, cache = mesh_equations_solver_cache(semi)
# Calc bounds inside elements
@threaded for element in eachelement(dg, cache)
var_minmax[:, :, element] .= typeminmax(eltype(var_minmax))
for j in eachnode(dg), i in eachnode(dg)
var_minmax[i, j, element] = typeminmax(eltype(var_minmax))
end

# Calculate bounds at Gauss-Lobatto nodes using u
for j in eachnode(dg), i in eachnode(dg)
Expand Down

0 comments on commit d854c50

Please sign in to comment.