Skip to content

Compress neighbor cell adjacency storage#182

Open
AhmedSalih3d wants to merge 1 commit into
BeforeLidDrivenCavityExamplefrom
codex/benchmark-adjacency-layout-performance
Open

Compress neighbor cell adjacency storage#182
AhmedSalih3d wants to merge 1 commit into
BeforeLidDrivenCavityExamplefrom
codex/benchmark-adjacency-layout-performance

Conversation

@AhmedSalih3d

Copy link
Copy Markdown
Owner

Motivation

  • Reduce allocations and pointer-chasing from Vector{Vector{Int}} per-cell neighbor lists by using a compact adjacency layout.
  • The stencil size is bounded (max 3^D - 1), so a fixed-size dense layout plus per-cell counts can improve cache locality in the inner neighbor loops.
  • Preserve existing neighbor-iteration ergonomics so calling code in hot loops requires minimal changes.

Description

  • Add CompressedNeighborCellLists (dense Matrix{Int} of shape (max_neighbors, n_cells) plus Counts::Vector{Int}) to store adjacency compactly.
  • Provide NeighborCellIndices iterator and Base.getindex so for NeighborIdx in NeighborCellLists[cell] remains valid.
  • Implement EnsureNeighborCellCapacity! and update BuildNeighborCellLists! to populate the compressed layout and return the structure.
  • Update alloc/rebuild sites in src/SPHCellList.jl to allocate CompressedNeighborCellLists(...) and accept the returned value from BuildNeighborCellLists!, and re-export CompressedNeighborCellLists from the top-level module.

Testing

  • Ran git diff --check which reported no whitespace/errors.
  • Ran julia --project=. -e 'using SPHExample' which precompiled and loaded the package successfully.
  • Ran a focused neighbor-list unit check with julia --project=. -e 'using Test; using SPHExample.SPHNeighborList; ... BuildNeighborCellLists!(...) ; @test collect(lists[2]) == [3,4]' which validated neighbor enumeration and succeeded.
  • Ran the full test suite with julia --project=. -e 'using Pkg; Pkg.test()', which errored in an existing time-stepping test due to a mismatched Δt method signature unrelated to the neighbor-list changes.

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