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

Fix n-body benchmark #525

Merged
merged 8 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
18 changes: 10 additions & 8 deletions examples/n_body/n_body_benchmark_trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ using Polyester

include("n_body_system.jl")

# Redefine interact in a more optimized way.
function TrixiParticles.interact!(du, u_particle_system, u_neighbor_system,
# Redefine interact in a more optimized way
function TrixiParticles.interact!(dv, v_particle_system, u_particle_system,
v_neighbor_system, u_neighbor_system,
neighborhood_search,
particle_system::NBodySystem,
neighbor_system::NBodySystem)
Expand All @@ -34,16 +35,15 @@ function TrixiParticles.interact!(du, u_particle_system, u_neighbor_system,
tmp1 = mass[neighbor] * tmp
tmp2 = mass[particle] * tmp

for i in 1:ndims(particle_system)
j = i + ndims(particle_system)
# This is slightly faster than du[...] += tmp1 * pos_diff[i]
du[j, particle] = muladd(tmp1, pos_diff[i], du[j, particle])
du[j, neighbor] = muladd(tmp2, -pos_diff[i], du[j, neighbor])
@inbounds for i in 1:ndims(particle_system)
# This is slightly faster than dv[...] += tmp1 * pos_diff[i]
dv[i, particle] = muladd(tmp1, pos_diff[i], dv[i, particle])
dv[i, neighbor] = muladd(tmp2, -pos_diff[i], dv[i, neighbor])
end
end
end

return du
return dv
end

# ==========================================================================================
Expand Down Expand Up @@ -98,6 +98,8 @@ function symplectic_euler!(velocity, coordinates, semi)
u[i] += 0.01 * du[i]
end
end

return v, u
end

# One RHS evaluation is so fast that timers make it multiple times slower.
Expand Down
2 changes: 1 addition & 1 deletion test/examples/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
@trixi_testset "n_body/n_body_benchmark_trixi.jl" begin
@test_nowarn_mod trixi_include(@__MODULE__,
joinpath(examples_dir(), "n_body",
"n_body_benchmark_trixi.jl"))
"n_body_benchmark_trixi.jl"))[r"WARNING: Method definition interact!*\n"]
end

@trixi_testset "n_body/n_body_benchmark_reference.jl" begin
Expand Down
Loading