0

After a new group is created, the lowest rank id is zero. How can I preserve the original ranks of processors?

#include <boost/mpi.hpp>

namespace bmpi = boost::mpi;

int main()
{
    MPI_Init(NULL, NULL);

    bmpi::communicator comm;
    bmpi::group group = comm.group();

    std::vector<int> to_be_excluded = {0};
    group = group.exclude(to_be_excluded.begin(), to_be_excluded.end());
    comm = bmpi::communicator(comm, group);

    if (comm) {
        std::cout << comm.rank() << std::endl; // want this to be original rank which is 1 not zero.
    }

    MPI_Finalize();
    return 0;
}
Shibli
  • 5,879
  • 13
  • 62
  • 126
  • 1
    I don't think you can, even if you drop your use of Boost. The Boost communicator creation routines don't seem to offer a way to specify the assignment of ranks within the new communicator to specific ranks from the parent communicator. Without Boost, using the bare C interface to MPI, you can specify the order (ie from `0..n`) in which processes are assigned ranks in the new communicator, but not an arbitrary mapping from one set of rank ids to a new set. Of course, each process in the new communicator knows its rank in both communicators, so you can track the assignments. – High Performance Mark Apr 04 '20 at 11:30
  • +1 on @HighPerformanceMark comment. Keep in mind the rank is local to a communicator, and they range from `0` to `communicator_size-1`, so "preserving the original rank" does not make sense in MPI. – Gilles Gouaillardet Apr 04 '20 at 11:47

0 Answers0