From c213dbfbf55b872a895bcea799610d41790f02d2 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:02:58 +0100 Subject: [PATCH] [Proof of Concept] Use symmetry to speed up the main loop --- src/nhs_grid.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/nhs_grid.jl b/src/nhs_grid.jl index 3b5dd266..2f785a93 100644 --- a/src/nhs_grid.jl +++ b/src/nhs_grid.jl @@ -372,6 +372,10 @@ end for neighbor_ in eachindex(neighbors) neighbor = @inbounds neighbors[neighbor_] + # Skip half of the neighbors and use symmetry below. + # Note that this only works when `system_coords == neighbor_system_coords`. + point <= neighbor || continue + # Making the following `@inbounds` yields a ~2% speedup on an NVIDIA H100. # But we don't know if `neighbor` (extracted from the cell list) is in bounds. neighbor_coords = extract_svector(neighbor_system_coords, @@ -390,6 +394,9 @@ end # Inline to avoid loss of performance # compared to not using `foreach_point_neighbor`. @inline f(point, neighbor, pos_diff, distance) + if point < neighbor + @inline f(neighbor, point, -pos_diff, distance) + end end end end