Question

is there a boost::MPI equivalent of the following C MPI code? I'm trying to port the following standard MPI code which is a basic master slave template found here. Following from the boost mpi documentation theres only 3 parameters , for an mpi_send or mpi_recv rank, tag and buffer.

while (work != NULL) {

    /* Receive results from a slave */

    MPI_Recv(&result,           /* message buffer */
             1,                 /* one data item */
             MPI_INT,        /* of type double real */
             MPI_ANY_SOURCE,    /* receive from any sender */
             MPI_ANY_TAG,       /* any type of message */
             MPI_COMM_WORLD,    /* default communicator */
             &status);          /* info about the received message */

    /* Send the slave a new work unit */

    MPI_Send(&work,             /* message buffer */
             1,                 /* one data item */
             MPI_INT,           /* data item is an integer */
             status.MPI_SOURCE, /* to who we just received from */
             WORKTAG,           /* user chosen message tag */
             MPI_COMM_WORLD);   /* default communicator */

    /* Get the next unit of work to be done */

    work = get_next_work_item();
  }
Was it helpful?

Solution

From the boost.MPI documentation:

  • MPI_ANY_SOURCE becomes any_source
  • MPI_ANY_TAG becomes any_tag

The communicator::recv() method returns an instance of the status class that provides all the information that you need:

  • status.MPI_SOURCE is returned by status::source()
  • status.MPI_TAG is returned by status::tag()

It also provides two cast operators to covert its content to MPI_Status structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top