Skip to content

Add functions mapreduce_neighbor and mapreduce_neighbor_unsafe#158

Open
efaulhaber wants to merge 5 commits into
mainfrom
ef/mapreduce-neighbor
Open

Add functions mapreduce_neighbor and mapreduce_neighbor_unsafe#158
efaulhaber wants to merge 5 commits into
mainfrom
ef/mapreduce-neighbor

Conversation

@efaulhaber
Copy link
Copy Markdown
Member

@efaulhaber efaulhaber commented May 25, 2026

This PR allows us to convert the awkward

dv_particle = Ref(zero(v_a))

foreach_neighbor(...) do particle, neighbor, pos_diff, distance
    ...
    dv_particle[] += result
end

to a cleaner

dv_particle = mapreduce_neighbor(+, ..., init=zero(v_a)) do particle, neighbor, pos_diff, distance
    ...
    return result
end

in trixi-framework/TrixiParticles.jl#1211.

This is necessary for vectorization on the CPU.

@efaulhaber efaulhaber self-assigned this May 25, 2026
@efaulhaber efaulhaber added the enhancement New feature or request label May 25, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.38%. Comparing base (f25b0ab) to head (110aef6).

Files with missing lines Patch % Lines
test/neighborhood_search.jl 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #158      +/-   ##
==========================================
+ Coverage   86.06%   86.38%   +0.31%     
==========================================
  Files          15       15              
  Lines         739      771      +32     
==========================================
+ Hits          636      666      +30     
- Misses        103      105       +2     
Flag Coverage Δ
unit 86.38% <95.74%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces mapreduce_neighbor / mapreduce_neighbor_unsafe as new public APIs to compute per-point reductions over neighbors, and refactors the existing neighbor-iteration internals so foreach_neighbor is implemented as a special case of the new map-reduce kernel.

Changes:

  • Add mapreduce_neighbor and mapreduce_neighbor_unsafe to the public API (exports) and implement them for all neighborhood-search backends.
  • Refactor backend-specific neighbor loops (GridNeighborhoodSearch, PrecomputedNeighborhoodSearch, and the generic fallback) to return a reduction value (mapreduce_neighbor_inner) and adapt foreach_neighbor to use it.
  • Update tests to use push! for neighbor collection and add allocation tests for foreach_neighbor / mapreduce_neighbor plus keyword-argument error checks.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/neighborhood_search.jl Fix neighbor list construction (push!) and add tests for mapreduce_neighbor(*), plus allocation and missing-init checks.
src/PointNeighbors.jl Export the new mapreduce_neighbor and mapreduce_neighbor_unsafe APIs.
src/nhs_precomputed.jl Implement reduction-returning neighbor loop for PrecomputedNeighborhoodSearch.
src/nhs_grid.jl Implement reduction-returning neighbor loop for GridNeighborhoodSearch.
src/neighborhood_search.jl Add the new APIs and refactor generic/unsafe neighbor iteration to use the map-reduce inner loop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/neighborhood_search.jl
Comment thread src/neighborhood_search.jl
@efaulhaber efaulhaber marked this pull request as ready for review May 28, 2026 10:05
@efaulhaber efaulhaber requested a review from svchb May 28, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants