...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::mpi::cartesian_communicator — An MPI communicator with a cartesian topology.
// In header: <boost/mpi/cartesian_communicator.hpp> class cartesian_communicator : public boost::mpi::communicator { public: // public member functions cartesian_communicator(const MPI_Comm &, comm_create_kind); cartesian_communicator(const communicator &, const cartesian_topology &, bool = false); cartesian_communicator(const cartesian_communicator &, const std::vector< int > &); int ndims() const; int rank(const std::vector< int > &) const; std::pair< int, int > shifted_ranks(int, int) const; std::vector< int > coordinates(int) const; void topology(cartesian_topology &, std::vector< int > &) const; cartesian_topology topology() const; int rank() const; };
A cartesian_communicator
is a communicator whose topology is expressed as a grid. Cartesian communicators have the same functionality as (intra)communicators, but also allow one to query the relationships among processes and the properties of the grid.
cartesian_communicator
public member functionscartesian_communicator(const MPI_Comm & comm, comm_create_kind kind);
Build a new Boost.MPI cartesian communicator based on the MPI communicator comm
with cartesian topology.
comm
may be any valid MPI communicator. If comm
is MPI_COMM_NULL, an empty communicator (that cannot be used for communication) is created and the kind
parameter is ignored. Otherwise, the kind
parameter determines how the Boost.MPI communicator will be related to comm:
If kind
is comm_duplicate
, duplicate comm
to create a new communicator. This new communicator will be freed when the Boost.MPI communicator (and all copies of it) is destroyed. This option is only permitted if the underlying MPI implementation supports MPI 2.0; duplication of intercommunicators is not available in MPI 1.x.
If kind
is comm_take_ownership
, take ownership of comm
. It will be freed automatically when all of the Boost.MPI communicators go out of scope.
If kind
is comm_attach
, this Boost.MPI communicator will reference the existing MPI communicator comm
but will not free comm
when the Boost.MPI communicator goes out of scope. This option should only be used when the communicator is managed by the user.
cartesian_communicator(const communicator & comm, const cartesian_topology & dims, bool reorder = false);
Create a new communicator whose topology is described by the given cartesian. The indices of the vertices in the cartesian will be assumed to be the ranks of the processes within the communicator. There may be fewer vertices in the cartesian than there are processes in the communicator; in this case, the resulting communicator will be a NULL communicator.
Parameters: 

cartesian_communicator(const cartesian_communicator & comm, const std::vector< int > & keep);
Create a new cartesian communicator whose topology is a subset of an existing cartesian cimmunicator.
Parameters: 

int ndims() const;
Retrive the number of dimension of the underlying toppology.
int rank(const std::vector< int > & coords) const;
Return the rank of the process at the given coordinates.
Parameters: 

std::pair< int, int > shifted_ranks(int dim, int disp) const;
Return the rank of the source and target destination process through a shift.
Parameters: 

std::vector< int > coordinates(int rk) const;
Provides the coordinates of the process with the given rank.
Parameters: 


Returns: 
the coordinates. 
void topology(cartesian_topology & dims, std::vector< int > & coords) const;
Retrieve the topology and coordinates of this process in the grid.
cartesian_topology topology() const;
Retrieve the topology of the grid.
int rank() const;Determine the rank of the executing process in a communicator.
This routine is equivalent to MPI_Comm_rank
.
Returns: 
The rank of the process in the communicator, which will be a value in [0, size()) 