I'm looking for something similar to the question asked here: MPI communicator as global variable.
The answer given there is essentially that MPI_COMM_WORLD
is a global variable.
Boost wraps its communicators nicely, and generates a communicator wrapper for MPI_COMM_WORLD
by default when constructing an object of type boost::mpi::communicator
. [Boost MPI tutorial]
My question:
If I want to access something given by the communicator, for example a process's rank, I can call
boost::mpi::communicator world;
int mpi_rank = world.rank();
This will also work in a separate function, outside of main.cpp
, etc. If I use the same constructor there, will I get the same mpi_rank
value in each case? More specifically, will the process with rank = 0
still have rank = 0
if I construct a new boost::mpi::communicator
object in a new file/function? It doesn't seem clear to me from the Boost documentation.