From 8b19ac7747bf5109d205fdd0af3bf4e1fcac375e Mon Sep 17 00:00:00 2001 From: Fei Yang <2501213217@stu.pku.edu.cn> Date: Thu, 28 May 2026 17:12:51 +0800 Subject: [PATCH] Parallelize neighbor list construction with OpenMP --- .../module_neighlist/bin_manager.cpp | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/source/source_cell/module_neighlist/bin_manager.cpp b/source/source_cell/module_neighlist/bin_manager.cpp index 2e64b49a881..84cdaa25951 100644 --- a/source/source_cell/module_neighlist/bin_manager.cpp +++ b/source/source_cell/module_neighlist/bin_manager.cpp @@ -118,13 +118,19 @@ void BinManager::build_atom_neighbors( { assert(atoms.size() == neighbor_list.numneigh.size()); - double sradius2 = sradius * sradius; + const double sradius2 = sradius * sradius; + const int natoms = static_cast(atoms.size()); neighbor_list.reset(); - for (int i = 0; i < atoms.size(); i++) + std::vector> neighbor_ids(natoms); + +#ifdef _OPENMP +#pragma omp parallel for schedule(dynamic, 16) +#endif + for (int i = 0; i < natoms; i++) { - std::vector neigh_tmp; + std::vector& neigh_tmp = neighbor_ids[i]; int ix = std::min( std::max(int((atoms[i].position_x - x_min) / bin_sizex), 0), @@ -174,7 +180,12 @@ void BinManager::build_atom_neighbors( } } } - int n = neigh_tmp.size(); + } + + for (int i = 0; i < natoms; i++) + { + const std::vector& neigh_tmp = neighbor_ids[i]; + int n = static_cast(neigh_tmp.size()); //std::cout<