|
FML
|
A container class for holding particles that are distributed across many CPUs and to easily deal with communication of these particles if they cross the domain boundary (simply call communicate_particles() at any time to do this) More...
#include <MPIParticles.h>
Data Structures | |
| class | iterator |
| Iterator for looping through all the active particles i.e. allow for(auto &&p: mpiparticles) | |
Public Member Functions | |
| iterator | begin () |
| Iterator: points to the first local particle. | |
| iterator | end () |
| Iterator: points to one past the last active local particle. | |
| void | create (T *part, size_t NumParts, size_t nallocate, double xmin_local, double xmax_local, bool all_tasks_has_the_same_particles) |
| Create MPIParticles from a set of particles. | |
| void | create (std::vector< T > &part, size_t nallocate, std::function< bool(T &)> selection_function) |
| Create from a vector of particles with a given selection function This could for example be that xmin < x < xmax and if particles have a type only select a particular type. | |
| void | move_from (Vector< T > &&part) |
| Moves a vector of particles into internal storage (so no copies are being done). | |
| void | create_particle_grid (int Npart_1D, double buffer_factor, double xmin_local, double xmax_local) |
| Create \( {\rm Npart}_{1D}^{\rm NDIM} \) particles in a rectangular grid spread across all tasks buffer_factor is how much extra to allocate in case particles moves xmin, xmax specifies the domain in [0,1] that the current task is responsible for This method only sets the positions of the particles not id or vel or anything else. | |
| MPIParticles ()=default | |
| operator bool () const | |
| Vector< T > & | get_particles () |
| Get reference to particle vector. | |
| T * | get_particles_ptr () |
| Get a pointer to the first particle. | |
| T & | operator[] (size_t i) |
| Access particles through indexing operator. | |
| T & | get_part (size_t i) |
| Get a reference to the i'th particle. | |
| auto | get_pos (size_t ipart, int idim) |
| Get the idim component of the position for particle ipart. | |
| auto | get_vel (size_t ipart, int idim) |
| Get the idim component of the velocity for particle ipart (if its available) | |
| size_t | get_npart_total () const |
| Total number of active particles across all tasks. | |
| size_t | get_npart () const |
| Number of active particles on the local task. | |
| void | communicate_particles (size_t max_message_bytes=std::numeric_limits< int >::max(), bool force_general=false) |
| Communicate particles across CPU boundaries. | |
| MigrationRoute | get_last_migration_route () const |
| Last route selected by communicate_particles (same on every rank). | |
| std::vector< double > | get_x_min_per_task () |
| Get a vector of xmin of the domain for each task. | |
| std::vector< double > | get_x_max_per_task () |
| Get a vector of xmax of the domain for each task. | |
| void | free () |
| Free all memory of the stored particles. | |
| void | add_memory_label (std::string name) |
| For memory logging add a tag to the vector we have allocated. | |
| void | dump_to_file (std::string fileprefix, size_t max_bytesize_buffer=100 *1000 *1000) |
| Dump data to file (internal format: a raw copy of the particles, one file fileprefix.X per task). | |
| void | load_from_file (std::string fileprefix) |
| Load data written by dump_to_file (same particle type and number of tasks) | |
| void | info () |
| Show some info about the class. | |
| void | sort_by_position (int nblocks_per_dim) |
| Reorder the local particles by position (see sort_particles_by_position) so that particles close in space are close in memory. | |
A container class for holding particles that are distributed across many CPUs and to easily deal with communication of these particles if they cross the domain boundary (simply call communicate_particles() at any time to do this)
Contains methods for setting up MPIParticles from a set of particles or creating regular grids of particles and so on
Templated on particle class. Particle must at a minimum have the methods
get_pos() : Ptr to position
int get_ndim() : How many dimensions pos have
If the particle has any dynamical allocations you must also provide (these are automatically provided otherwise):
get_particle_byte_size() : How many bytes does the particle store
append_to_buffer(char *) : append all the particle data to a char array moving buffer forward as we read
assign_from_buffer(char *) : assign data to a particle after it has been received moving buffer forward as we do this
Compile time defines:
DEBUG_MPIPARTICLES : Show some info when running
External variables/methods we rely on:
int ThisTask;
int NTasks;
assert_mpi(Expr, Msg)
T power(T base, int exponent);
Definition at line 78 of file MPIParticles.h.
|
default |
| void FML::PARTICLE::MPIParticles< T >::add_memory_label | ( | std::string | name | ) |
For memory logging add a tag to the vector we have allocated.
Definition at line 348 of file MPIParticles.h.
|
inline |
Iterator: points to the first local particle.
Definition at line 127 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::communicate_particles | ( | size_t | max_message_bytes = std::numeric_limits<int>::max(), |
| bool | force_general = false ) |
Communicate particles across CPU boundaries.
Definition at line 729 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::create | ( | std::vector< T > & | part, |
| size_t | nallocate, | ||
| std::function< bool(T &)> | selection_function ) |
Create from a vector of particles with a given selection function This could for example be that xmin < x < xmax and if particles have a type only select a particular type.
Definition at line 378 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::create | ( | T * | part, |
| size_t | NumParts, | ||
| size_t | nallocate, | ||
| double | xmin_local, | ||
| double | xmax_local, | ||
| bool | all_tasks_has_the_same_particles ) |
Create MPIParticles from a set of particles.
We only keep the particles in part that are in the correct x-range if all_tasks_has_the_same_particles is true nallocate is the total amount of particles we allocate for locally (we do buffered read if only one task reads particles to avoid having to allocate too much).
| [in] | part | Pointer to a set of particles |
| [in] | NumParts | Number of particles we have |
| [in] | nallocate | How many particles to allocate for locally (in case we want to have a buffer) |
| [in] | xmin_local | The min of the x-range in [0,1] the current task is responsible for |
| [in] | xmax_local | The max of the x-range in [0,1] the current task is responsible for |
| [in] | all_tasks_has_the_same_particles | Set this to be true if all tasks has the same set of particles (e.g. they come from reading the same file). If false then we assume all tasks that has particles has distinct particles |
Definition at line 422 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::create_particle_grid | ( | int | Npart_1D, |
| double | buffer_factor, | ||
| double | xmin_local, | ||
| double | xmax_local ) |
Create \( {\rm Npart}_{1D}^{\rm NDIM} \) particles in a rectangular grid spread across all tasks buffer_factor is how much extra to allocate in case particles moves xmin, xmax specifies the domain in [0,1] that the current task is responsible for This method only sets the positions of the particles not id or vel or anything else.
Definition at line 588 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::dump_to_file | ( | std::string | fileprefix, |
| size_t | max_bytesize_buffer = 100 * 1000 * 1000 ) |
Dump data to file (internal format: a raw copy of the particles, one file fileprefix.X per task).
Meant for checkpointing within the same program: the files can only be read back with load_from_file using the same particle type, the same number of tasks and the same machine architecture. For portable output use e.g. GADGET (HDF5) files (GadgetUtils)
Definition at line 1019 of file MPIParticles.h.
|
inline |
Iterator: points to one past the last active local particle.
Definition at line 129 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::free | ( | ) |
Free all memory of the stored particles.
Definition at line 355 of file MPIParticles.h.
|
inline |
Last route selected by communicate_particles (same on every rank).
Definition at line 198 of file MPIParticles.h.
| size_t FML::PARTICLE::MPIParticles< T >::get_npart | ( | ) | const |
Number of active particles on the local task.
Definition at line 546 of file MPIParticles.h.
| size_t FML::PARTICLE::MPIParticles< T >::get_npart_total | ( | ) | const |
Total number of active particles across all tasks.
Definition at line 551 of file MPIParticles.h.
| T & FML::PARTICLE::MPIParticles< T >::get_part | ( | size_t | i | ) |
Get a reference to the i'th particle.
Definition at line 541 of file MPIParticles.h.
| Vector< T > & FML::PARTICLE::MPIParticles< T >::get_particles | ( | ) |
Get reference to particle vector.
NB: due to we allow a buffer the size of the vector returned is not equal to the number of active particles!
Definition at line 556 of file MPIParticles.h.
| T * FML::PARTICLE::MPIParticles< T >::get_particles_ptr | ( | ) |
Get a pointer to the first particle.
Definition at line 561 of file MPIParticles.h.
| auto FML::PARTICLE::MPIParticles< T >::get_pos | ( | size_t | ipart, |
| int | idim ) |
Get the idim component of the position for particle ipart.
Definition at line 688 of file MPIParticles.h.
| auto FML::PARTICLE::MPIParticles< T >::get_vel | ( | size_t | ipart, |
| int | idim ) |
Get the idim component of the velocity for particle ipart (if its available)
Definition at line 696 of file MPIParticles.h.
| std::vector< double > FML::PARTICLE::MPIParticles< T >::get_x_max_per_task | ( | ) |
Get a vector of xmax of the domain for each task.
Definition at line 571 of file MPIParticles.h.
| std::vector< double > FML::PARTICLE::MPIParticles< T >::get_x_min_per_task | ( | ) |
Get a vector of xmin of the domain for each task.
Definition at line 566 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::info | ( | ) |
Show some info about the class.
Definition at line 301 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::load_from_file | ( | std::string | fileprefix | ) |
Load data written by dump_to_file (same particle type and number of tasks)
Definition at line 1090 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::move_from | ( | Vector< T > && | part | ) |
Moves a vector of particles into internal storage (so no copies are being done).
The extra storage (if needed) needs to already be in part! Assumes we have distinct particles on different tasks. This saves having to do allocations and copies, but its safer and flexible to just use create() so its best to not use this unless you really need to
Definition at line 361 of file MPIParticles.h.
|
explicit |
Definition at line 296 of file MPIParticles.h.
| T & FML::PARTICLE::MPIParticles< T >::operator[] | ( | size_t | i | ) |
Access particles through indexing operator.
Definition at line 576 of file MPIParticles.h.
| void FML::PARTICLE::MPIParticles< T >::sort_by_position | ( | int | nblocks_per_dim | ) |
Reorder the local particles by position (see sort_particles_by_position) so that particles close in space are close in memory.
Speeds up assigning particles to a grid and interpolating from it
Definition at line 291 of file MPIParticles.h.