MPIbuf_array

MPIbuf_array is a convenience type for managing a group of messages:

  class MPIbuf_array
  {
  public:
    
    MPIbuf_array(unsigned n);
    MPIbuf& operator[](unsigned i);

    bool testall();
    int testany();
    vector<int> testsome();
    void waitall();
    int waitany();
    vector<int> waitsome();
  };

The testall(), testany etc methods perform the MPI equivalent call on the group of messages.

MPIbuf_array is useful for managing an all-to-all calculation, as per the following typical example:

    {
        tag++;
        MPIbuf_array sendbuf(nprocs());
        for (unsigned proc=0; proc<nprocs(); proc++)
          {
            if (proc==myid()) continue;
            sendbuf[proc] << requests[proc] << isend(proc,tag);
          }
        for (int i=0; i<nprocs()-1; i++)
          {
            MPIbuf b; 
            b.get(MPI_ANY_SOURCE,tag);
            b >> rec_req[b.proc];
          }
     }

Note that the outer pair of braces that all messages have been sent and received in the group. Using an explicit tag is useful to prevent message groups from interfering with each other.