vSMC
vSMC: Scalable Monte Carlo
|
Particle::value_type subtype using MPI. More...
#include <vsmc/internal/forward.hpp>
Public Types | |
typedef ID | mpi_id |
typedef traits::SizeTypeTrait< BaseState >::type | size_type |
typedef WeightSetMPI< typename traits::WeightSetTypeTrait< BaseState >::type, ID > | weight_set_type |
Public Member Functions | |
StateMPI (size_type N) | |
template<typename IntType > | |
void | copy (size_type N, const IntType *copy_from) |
Copy particles. More... | |
size_type | global_id (size_type local_id) const |
Transfer a local particle id on this node into a global particle id. More... | |
size_type | global_size () const |
The number of particles on all nodes. More... | |
bool | is_local (size_type global_id) const |
Given a global particle id check if it is on this node More... | |
size_type | local_id (size_type global_id) const |
Transfer a global particle id into a local particle id (possibly not on this node, use rank to get the rank of its node) More... | |
size_type | offset () const |
The number of particles on nodes with ranks less than the rank of this node. More... | |
int | rank (size_type global_id) const |
Given a global particle id return the rank of the node it belongs. More... | |
const ::boost::mpi::communicator & | world () const |
A duplicated MPI communicator for this state value object. More... | |
Protected Member Functions | |
void | copy_inter_node (const std::vector< std::pair< int, size_type > > ©_recv, const std::vector< std::pair< int, size_type > > ©_send) |
Perform global copy. More... | |
int | copy_tag () const |
The MPI recv/send tag used by copy_inter_node More... | |
void | copy_this_node (size_type N, const size_type *copy_from, std::vector< std::pair< int, size_type > > ©_recv, std::vector< std::pair< int, size_type > > ©_send) |
Perform local copy. More... | |
Particle::value_type subtype using MPI.
Definition at line 72 of file forward.hpp.
typedef ID vsmc::StateMPI< BaseState, ID >::mpi_id |
Definition at line 239 of file backend_mpi.hpp.
typedef traits::SizeTypeTrait<BaseState>::type vsmc::StateMPI< BaseState, ID >::size_type |
Definition at line 236 of file backend_mpi.hpp.
typedef WeightSetMPI<typename traits::WeightSetTypeTrait<BaseState>::type, ID> vsmc::StateMPI< BaseState, ID >::weight_set_type |
Definition at line 238 of file backend_mpi.hpp.
|
inlineexplicit |
Definition at line 241 of file backend_mpi.hpp.
|
inline |
Copy particles.
N | The number of particles on all nodes |
copy_from | A vector of length N , for each particle with global id to , copy_from[to] is the global id of the particle it shall copy. |
The BaseState
type is required to have the following members - state_pack_type
: A type that used to pack state values. It shall be serializable. That is, a state_pack_type
object is acceptable by boost::mpi::communicator::send
etc. Both StateMatrix::state_pack_type and StateTuple::state_pack_type satisfy this requirement if their template type parameter types are serializable. For user defined types, see document of Boost.Serialize of how to serialize a class object.
state_pack
state_pack_type
object.state_unpack
state_pack_type
object, unpack it into the given position on this node. If C++11 rvalue reference is supported, then an rvalue version of this function can be defined to improved the performance as pack
will be passed as an rvalue. e.g., state_pack_type
needs to explicitly define move constructor or assignment operator, care shall be taken to make sure that after the move pack
is still a valid, assignable object.In vSMC, the resampling algorithms generate the number of replications of each particle. Particles with replication zero need to copy other particles. The vector of the number of replications is transfered to copy_from
by Particle::resample, and it is generated in such a way that each particle will copy from somewhere close to itself. Therefore, transferring between nodes is minimized.
This default implementation perform three stages of copy.
copy_from
on node 0
and broadcast it to all nodes.A derived class can override this copy
method. For the following possible reasons,
this->state_pack(id)
and `this->state_unpack(id, pack) is not too expansive, and inter-node copy is rare anyway. If this is not the case, then it can be a performance bottle neck. Definition at line 320 of file backend_mpi.hpp.
|
inlineprotected |
Perform global copy.
copy_recv | The output vector copy_recv from copy_this_node |
copy_send | The output vector copy_send from copy_this_node |
Definition at line 456 of file backend_mpi.hpp.
|
inlineprotected |
The MPI recv/send tag used by copy_inter_node
Definition at line 392 of file backend_mpi.hpp.
|
inlineprotected |
Perform local copy.
N | The number of particles on all nodes |
copy_from | The beginning of the copy_from vector |
copy_recv | All particles that shall be received at this node |
copy_send | All particles that shall be send from this node |
copy_from
is a pointer that can access a vector of size N
. For each to
in the range 0
to N - 1
to
and from = copy_from[to]
are particles on this node, use BaseState::copy
to copy the parties. Otherwise,to
is a particle on this node, insert a pair into copy_recv
, whose values are the rank of the node from which this node shall receive the particle and the particle id on this node where the particle received shall be unpacked. Otherwise,from = copy_from[to]
is a particle on this node, insert a pair into copy_send
, whose values are the rank of the node to which this node shall send the particle and the particle id on this node where the particle sent shall be packed. Otherwise do nothing.It is important the the vector accessed through copy_from_first
is the same for all nodes. Otherwise the behavior is undefined.
Definition at line 417 of file backend_mpi.hpp.
|
inline |
Transfer a local particle id on this node into a global particle id.
Definition at line 387 of file backend_mpi.hpp.
|
inline |
The number of particles on all nodes.
Definition at line 338 of file backend_mpi.hpp.
|
inline |
Given a global particle id check if it is on this node
Definition at line 362 of file backend_mpi.hpp.
|
inline |
Transfer a global particle id into a local particle id (possibly not on this node, use rank
to get the rank of its node)
Definition at line 367 of file backend_mpi.hpp.
|
inline |
The number of particles on nodes with ranks less than the rank of this node.
Definition at line 342 of file backend_mpi.hpp.
|
inline |
Given a global particle id return the rank of the node it belongs.
Definition at line 346 of file backend_mpi.hpp.
|
inline |
A duplicated MPI communicator for this state value object.
Definition at line 335 of file backend_mpi.hpp.