Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread Parallel Reduction for integrate_via_indices #2201

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/callbacks_step/analysis_dg1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,51 +120,52 @@ function calc_error_norms(func, u, t, analyzer,
end

function integrate_via_indices(func::Func, u,
mesh::StructuredMesh{1}, equations, dg::DGSEM, cache,
mesh::TreeMesh{1}, equations, dg::DGSEM, cache,
ranocha marked this conversation as resolved.
Show resolved Hide resolved
args...; normalize = true) where {Func}
@unpack weights = dg.basis

# Initialize integral with zeros of the right shape
integral = zero(func(u, 1, 1, equations, dg, args...))
total_volume = zero(real(mesh))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=(+, integral) for element in eachelement(dg, cache)
volume_jacobian_ = volume_jacobian(element, mesh, cache)
for i in eachnode(dg)
jacobian_volume = abs(inv(cache.elements.inverse_jacobian[i, element]))
integral += jacobian_volume * weights[i] *
integral += volume_jacobian_ * weights[i] *
func(u, i, element, equations, dg, args...)
total_volume += jacobian_volume * weights[i]
end
end

# Normalize with total volume
if normalize
integral = integral / total_volume
integral = integral / total_volume(mesh)
end

return integral
end

function integrate_via_indices(func::Func, u,
mesh::TreeMesh{1}, equations, dg::DGSEM, cache,
mesh::StructuredMesh{1}, equations, dg::DGSEM, cache,
args...; normalize = true) where {Func}
@unpack weights = dg.basis

# Initialize integral with zeros of the right shape
integral = zero(func(u, 1, 1, equations, dg, args...))
total_volume = zero(real(mesh))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
volume_jacobian_ = volume_jacobian(element, mesh, cache)
@batch reduction=((+, integral), (+, total_volume)) for element in eachelement(dg,
cache)
for i in eachnode(dg)
integral += volume_jacobian_ * weights[i] *
jacobian_volume = abs(inv(cache.elements.inverse_jacobian[i, element]))
integral += jacobian_volume * weights[i] *
func(u, i, element, equations, dg, args...)
total_volume += jacobian_volume * weights[i]
end
end

# Normalize with total volume
if normalize
integral = integral / total_volume(mesh)
integral = integral / total_volume
end

return integral
Expand Down
5 changes: 3 additions & 2 deletions src/callbacks_step/analysis_dg2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function integrate_via_indices(func::Func, u,
integral = zero(func(u, 1, 1, 1, equations, dg, args...))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=(+, integral) for element in eachelement(dg, cache)
volume_jacobian_ = volume_jacobian(element, mesh, cache)
for j in eachnode(dg), i in eachnode(dg)
integral += volume_jacobian_ * weights[i] * weights[j] *
Expand Down Expand Up @@ -219,7 +219,8 @@ function integrate_via_indices(func::Func, u,
total_volume = zero(real(mesh))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=((+, integral), (+, total_volume)) for element in eachelement(dg,
cache)
for j in eachnode(dg), i in eachnode(dg)
volume_jacobian = abs(inv(cache.elements.inverse_jacobian[i, j, element]))
integral += volume_jacobian * weights[i] * weights[j] *
Expand Down
2 changes: 1 addition & 1 deletion src/callbacks_step/analysis_dg2d_parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function integrate_via_indices(func::Func, u,
volume = zero(real(mesh))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=((+, integral), (+, volume)) for element in eachelement(dg, cache)
for j in eachnode(dg), i in eachnode(dg)
volume_jacobian = abs(inv(cache.elements.inverse_jacobian[i, j, element]))
integral += volume_jacobian * weights[i] * weights[j] *
Expand Down
5 changes: 3 additions & 2 deletions src/callbacks_step/analysis_dg3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function integrate_via_indices(func::Func, u,
integral = zero(func(u, 1, 1, 1, 1, equations, dg, args...))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=(+, integral) for element in eachelement(dg, cache)
volume_jacobian_ = volume_jacobian(element, mesh, cache)
for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)
integral += volume_jacobian_ * weights[i] * weights[j] * weights[k] *
Expand Down Expand Up @@ -246,7 +246,8 @@ function integrate_via_indices(func::Func, u,
total_volume = zero(real(mesh))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=((+, integral), (+, total_volume)) for element in eachelement(dg,
cache)
for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)
volume_jacobian = abs(inv(cache.elements.inverse_jacobian[i, j, k, element]))
integral += volume_jacobian * weights[i] * weights[j] * weights[k] *
Expand Down
2 changes: 1 addition & 1 deletion src/callbacks_step/analysis_dg3d_parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function integrate_via_indices(func::Func, u,
volume = zero(real(mesh))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=((+, integral), (+, volume)) for element in eachelement(dg, cache)
for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)
volume_jacobian = abs(inv(cache.elements.inverse_jacobian[i, j, k, element]))
integral += volume_jacobian * weights[i] * weights[j] * weights[k] *
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/fdsbp_tree/fdsbp_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function integrate_via_indices(func::Func, u,
integral = zero(func(u, 1, 1, equations, dg, args...))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=(+, integral) for element in eachelement(dg, cache)
volume_jacobian_ = volume_jacobian(element, mesh, cache)
for i in eachnode(dg)
integral += volume_jacobian_ * weights[i] *
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/fdsbp_tree/fdsbp_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ function integrate_via_indices(func::Func, u,
integral = zero(func(u, 1, 1, 1, equations, dg, args...))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=(+, integral) for element in eachelement(dg, cache)
volume_jacobian_ = volume_jacobian(element, mesh, cache)
for j in eachnode(dg), i in eachnode(dg)
integral += volume_jacobian_ * weights[i] * weights[j] *
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/fdsbp_tree/fdsbp_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function integrate_via_indices(func::Func, u,
integral = zero(func(u, 1, 1, 1, 1, equations, dg, args...))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=(+, integral) for element in eachelement(dg, cache)
volume_jacobian_ = volume_jacobian(element, mesh, cache)
for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)
integral += volume_jacobian_ * weights[i] * weights[j] * weights[k] *
Expand Down
3 changes: 2 additions & 1 deletion src/solvers/fdsbp_unstructured/fdsbp_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ function integrate_via_indices(func::Func, u,
total_volume = zero(real(mesh))

# Use quadrature to numerically integrate over entire domain
for element in eachelement(dg, cache)
@batch reduction=((+, integral), (+, total_volume)) for element in eachelement(dg,
cache)
for j in eachnode(dg), i in eachnode(dg)
volume_jacobian = abs(inv(cache.elements.inverse_jacobian[i, j, element]))
integral += volume_jacobian * weights[i] * weights[j] *
Expand Down
Loading