2929#include " BoxGeometry.hpp"
3030#include " LocalBox.hpp"
3131#include " Particle.hpp"
32+ #include " aosoa_pack.hpp"
3233#include " cell_system/CellStructureType.hpp"
3334#include " communication.hpp"
35+ #include " custom_verlet_list.hpp"
3436#include " lees_edwards/lees_edwards.hpp"
3537#include " particle_enumeration.hpp"
3638#include " particle_reduction.hpp"
4345
4446#include < boost/mpi/collectives/all_reduce.hpp>
4547
48+ #ifdef SHARED_MEMORY_PARALLELISM
49+ #include < Cabana_Core.hpp>
50+ #include < Cabana_NeighborList.hpp>
51+ #include < Kokkos_Core.hpp>
52+ #include < omp.h>
53+ #endif
54+
4655#include < algorithm>
4756#include < cassert>
4857#include < cstddef>
5766#include < variant>
5867#include < vector>
5968
69+ CellStructure::~CellStructure () {
6070#ifdef SHARED_MEMORY_PARALLELISM
61- #include " aosoa_pack.hpp"
62- #include " custom_verlet_list.hpp"
63- #include < Cabana_Core.hpp>
64- #include < Cabana_NeighborList.hpp>
65- #include < Kokkos_Core.hpp>
71+ clear_local_properties ();
72+ // Kokkos handle can only be freed after all Cabana containers have been freed
73+ m_kokkos_handle.reset ();
6674#endif
75+ }
6776
68- CellStructure::~CellStructure () {
6977#ifdef SHARED_MEMORY_PARALLELISM
70- if (m_local_force) {
71- m_local_force.reset ();
72- }
78+ void CellStructure::clear_local_properties () {
79+ m_local_force.reset ();
7380#ifdef ROTATION
74- if (m_local_torque) {
75- m_local_torque.reset ();
76- }
81+ m_local_torque.reset ();
7782#endif
7883#ifdef NPT
79- if (m_local_virial) {
80- m_local_virial.reset ();
81- }
82- #endif
83- if (m_aosoa) {
84- m_aosoa.reset ();
85- }
86- if (m_particle_storage) {
87- m_particle_storage.reset ();
88- }
89- if (m_verlet_list_cabana) {
90- m_verlet_list_cabana.reset ();
91- }
92- // Kokkos handle can be freed after all Cabana containers have been freed
93- m_kokkos_handle.reset ();
84+ m_local_virial.reset ();
9485#endif
86+ m_aosoa.reset ();
87+ m_particle_storage.reset ();
88+ m_verlet_list_cabana.reset ();
89+ m_rebuild_verlet_list_cabana = true ;
9590}
9691
97- #ifdef SHARED_MEMORY_PARALLELISM
98-
9992void CellStructure::set_kokkos_handle (
10093 std::shared_ptr<Communication::KokkosHandle> handle) {
10194 m_kokkos_handle = std::move (handle);
@@ -123,9 +116,10 @@ static auto estimate_max_counts(int max_prefactor, double pair_cutoff,
123116 return max_counts;
124117}
125118
126- void CellStructure::rebuild_local_properties (std::size_t const num_threads,
127- double const pair_cutoff) {
119+ void CellStructure::rebuild_local_properties (double const pair_cutoff) {
128120 assert (m_kokkos_handle);
121+ using execution_space = Kokkos::DefaultExecutionSpace;
122+ auto const num_threads = execution_space ().concurrency ();
129123 auto const num_part = get_unique_particles ().size ();
130124 m_local_force =
131125 std::make_unique<ForceType>(" local_force" , num_part, num_threads);
@@ -145,13 +139,17 @@ void CellStructure::rebuild_local_properties(std::size_t const num_threads,
145139 m_verlet_list_cabana = std::make_unique<ListType>(0ul , num_part, max_counts);
146140}
147141
142+ void CellStructure::reset_local_force () {
143+ Kokkos::deep_copy (get_local_force (), 0 .);
144+ }
145+
148146void CellStructure::reset_local_properties () {
149- Kokkos::deep_copy (get_local_force (), 0 );
147+ Kokkos::deep_copy (get_local_force (), 0 . );
150148#ifdef ROTATION
151- Kokkos::deep_copy (get_local_torque (), 0 );
149+ Kokkos::deep_copy (get_local_torque (), 0 . );
152150#endif
153151#ifdef NPT
154- Kokkos::deep_copy (get_local_virial (), 0 );
152+ Kokkos::deep_copy (get_local_virial (), 0 . );
155153#endif
156154}
157155
@@ -490,12 +488,12 @@ bool CellStructure::check_resort_required(
490488 Utils::Vector3d const &additional_offset) const {
491489 auto const lim = Utils::sqr (m_verlet_skin / 2 .) - additional_offset.norm2 ();
492490
493- Reduction::AddPartialResultKernel<bool > add_partial = [lim](Particle const &p,
494- bool &result ) {
495- if ((p.pos () - p.pos_at_last_verlet_update ()).norm2 () > lim) {
496- result = true ;
497- }
498- };
491+ Reduction::AddPartialResultKernel<bool > add_partial =
492+ [lim]( bool &result, Particle const &p ) {
493+ if ((p.pos () - p.pos_at_last_verlet_update ()).norm2 () > lim) {
494+ result = true ;
495+ }
496+ };
499497
500498 Reduction::ReductionOp<bool > reduce_op = [](bool &acc, bool const &val) {
501499 acc |= val;
0 commit comments