perf/Optimize neighbor-list construction with OpenMP#7527
Open
Audrey-777 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves molecular-dynamics neighbor-list construction performance by introducing an OpenMP-enabled count/allocate/fill path in BinManager::build_atom_neighbors(), while keeping serial behavior for small/single-thread/OpenMP-OFF cases. It also adds lightweight timing instrumentation around key neighbor-search phases to make the runtime impact visible in profiling.
Changes:
- Add an OpenMP parallel neighbor-list build path using per-atom counting, serial allocation via
PageAllocator, then parallel fill while preserving neighbor order. - Factor out the bin-scan logic into a reusable
BinManager::visit_neighbors()helper to avoid duplicating traversal code between serial and parallel paths. - Add
ModuleBase::timerstart/end instrumentation inNeighborSearchandBinManagerhot-path methods.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| source/source_cell/module_neighlist/neighbor_search.cpp | Adds timers around set_member_variables(), init(), and build_neighbors() to profile neighbor-search stages. |
| source/source_cell/module_neighlist/bin_manager.h | Declares visit_neighbors() helper to share bin traversal logic used by both serial and OpenMP neighbor building. |
| source/source_cell/module_neighlist/bin_manager.cpp | Implements the OpenMP count/allocate/fill neighbor build path, the shared visit_neighbors() traversal, and timers around binning/build steps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes MD neighbor-list construction in
BinManager::build_atom_neighbors().For larger OpenMP runs, the neighbor-list build now uses a conservative count / allocate / fill flow:
PageAllocator.Small systems, single-thread runs, and OpenMP-disabled builds keep the serial path.
Correctness
The implementation preserves:
PageAllocatorownership.firstneigh_[i] == nullptrfor zero-neighbor atoms.Performance
Environment: 8 physical cores / 16 logical CPUs, Intel Xeon Platinum 8163,
np=1.2048 atom LJ NVE, 200 steps
10.30 s -> 9.35 s, about1.10x.BinManager::build_atom_neighbors:1.26 s -> 0.31 s, about4.06x.8192 atom LJ NVE, 100 steps
24.36 s -> 18.87 s, about1.29x.BinManager::build_atom_neighbors:2.67 s -> 0.62 s, about4.31x.Repeat check
11.16 s -> 10.13 s, about1.10x.24.01 s -> 19.95 s, about1.20x.Final energy, potential, kinetic, temperature, and pressure matched across tested thread counts.
Tests
git diff --check6dba4951c: passed