27#include "communication.hpp"
29#include "system/System.hpp"
35#include <boost/serialization/array.hpp>
36#include <boost/serialization/is_bitwise_serializable.hpp>
37#include <boost/serialization/split_free.hpp>
43void GpuParticleData::enable_particle_transfer() {
44 if (m_need_particles_update and not m_communication_enabled) {
46 gpu_init_particle_comm();
48 m_communication_enabled =
true;
52void GpuParticleData::copy_particles_to_device() {
54 copy_particles_to_device(cell_structure.local_particles(),
::this_node);
60 result = has_compatible_device_impl();
69namespace serialization {
70template <
typename Archive>
72 ar >> make_array(
reinterpret_cast<char *
>(&p),
75template <
typename Archive>
77 ar << make_array(reinterpret_cast<char const *>(&p),
89 for (
auto const &p : particles) {
90 buffer[i].p =
static_cast<Utils::Vector3f>(box.folded_position(p.pos()));
95 buffer[i].q =
static_cast<float>(p.q());
97 buffer[i].identity = p.id();
102void GpuParticleData::gather_particle_data(
108 static std::vector<GpuParticle> buffer;
109 buffer.resize(n_part);
115 particle_data_host.resize(n_part);
133 std::span<const float> forces,
134 std::span<const float> torques) {
136 for (
auto &p : particles) {
137 for (std::size_t j = 0ul; j < 3ul; j++) {
138 p.force()[j] +=
static_cast<double>(forces[3ul * i + j]);
140 p.torque()[j] +=
static_cast<double>(torques[3ul * i + j]);
158void GpuParticleData::particles_scatter_forces(
159 ParticleRange const &particles, std::span<float> host_forces,
160 std::span<float> host_torques)
const {
163 auto const n_elements =
static_cast<int>(size);
166 static std::vector<float> buffer_forces;
167 static std::vector<float> buffer_torques;
169 buffer_forces.resize(size);
172 buffer_torques.resize(size);
std::vector< T, CudaHostAllocator< T > > pinned_vector
static void add_forces_and_torques(ParticleRange const &particles, std::span< const float > forces, std::span< const float > torques)
Add a flat force (and torque) array to a range of particles.
static void pack_particles(ParticleRange const &particles, GpuParticleData::GpuParticle *buffer)
Vector implementation and trait types for boost qvm interoperability.
Particle data communication manager for the GPU.
bool has_compatible_device() const
base_type::size_type size() const
std::shared_ptr< CellStructure > cell_structure
std::shared_ptr< BoxGeometry > box_geo
boost::mpi::communicator comm_cart
The communicator.
int this_node
The number of this node.
This file contains the defaults for ESPResSo.
ParticleRange particles(std::span< Cell *const > cells)
void gather_buffer(std::vector< T, Allocator > &buffer, boost::mpi::communicator const &comm, int root=0)
Gather buffer with different size on each node.
void scatter_buffer(T *buffer, int n_elem, boost::mpi::communicator comm, int root=0)
Scatter buffer with different size on each node.
void load(Archive &ar, GpuParticleData::GpuParticle &p, unsigned const)
void save(Archive &ar, GpuParticleData::GpuParticle const &p, unsigned const)
Subset of Particle which is copied to the GPU.