ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
for_each_particle.hpp
Go to the documentation of this file.
1
2/*
3 * Copyright (C) 2010-2026 The ESPResSo project
4 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
5 * Max-Planck-Institute for Polymer Research, Theory Group
6 *
7 * This file is part of ESPResSo.
8 *
9 * ESPResSo is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * ESPResSo is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#pragma once
24
26
27#include <Kokkos_Core.hpp>
28
29#include <span>
30
31inline void CellStructure::parallel_for_each_particle_impl(
32 std::span<Cell *const> cells, ParticleCallback auto &&f) const {
33 if (cells.size() > 1) {
34 Kokkos::parallel_for( // loop over cells
35 "for_each_local_particle",
36 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(std::size_t{0},
37 cells.size()),
38 [&](auto cell_idx) {
39 for (auto &p : cells[cell_idx]->particles())
40 f(p);
41 });
42 } else if (cells.size() == 1) {
43 auto &particles = cells.front()->particles();
44 Kokkos::parallel_for( // loop over particles
45 "for_each_local_particle",
46 Kokkos::RangePolicy<Kokkos::DefaultHostExecutionSpace>(
47 std::size_t{0}, particles.size()),
48 [&](auto part_idx) { f(*(particles.begin() + part_idx)); });
49 }
50}
base_type::size_type size() const
ParticleRange particles(std::span< Cell *const > cells)