Skip to content

Add cell-pair (pairwise) neighbor loop and pairwise interaction helpers#170

Open
AhmedSalih3d wants to merge 7 commits intocodex/refactor-to-avoid-if-statementfrom
codex/optimize-neighbor-loop-performance
Open

Add cell-pair (pairwise) neighbor loop and pairwise interaction helpers#170
AhmedSalih3d wants to merge 7 commits intocodex/refactor-to-avoid-if-statementfrom
codex/optimize-neighbor-loop-performance

Conversation

@AhmedSalih3d
Copy link
Owner

Motivation

  • Reduce redundant work by switching to a cell-pair / pairwise accumulation path so each i,j interaction is evaluated once and both particles are updated, giving ~2× savings for symmetric interactions in the single-threaded case.

Description

  • Add NeighborLoopPairwise! variants that perform symmetric pairwise accumulation for the combinations of shifting and kernel-output modes, and zero/fill shared arrays before accumulation.
  • Add ComputeInteractionsPairwise! and ComputeInteractionsPairwiseNoKernel! helpers that compute and return symmetric contributions for density diffusion, pressure/viscous acceleration, kernel output, and shifting terms in one call per pair.
  • Update SimulationLoop to dispatch to the pairwise path when Threads.nthreads() == 1 and keep the original per-particle threaded path for multi-threaded runs.
  • Use symmetric accumulation (add contributions to both i and j) and compute AccelerationMax from the final accumulated accelerations.

Testing

  • No automated tests were run against the modified code.
  • Commands executed while implementing and inspecting the change (all completed successfully): rg -n "ComputeInteractionsPerParticle" -S src, sed -n '320,620p' src/SPHCellList.jl, rg -n "compute_viscosity" -S src, sed -n '1,200p' src/SPHViscosityModels.jl, rg -n "compute_density_diffusion" -S src, sed -n '1,220p' src/SPHDensityDiffusionModels.jl, rg -n "Scratch|scratch|Thread" src/SPHCellList.jl src -S, sed -n '1,120p' src/PreProcess.jl, nl -ba src/SPHCellList.jl | sed -n '30,280p', nl -ba src/SPHCellList.jl | sed -n '660,980p', nl -ba src/SPHCellList.jl | sed -n '1260,1420p', git add src/SPHCellList.jl, and git commit -m "Add cell-pair neighbor loop path".

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant