Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] MPI and C++ - now Send and Receive of Classes and STL containers
From: John Phillips (phillips_at_[hidden])
Date: 2009-07-06 23:00:09

Luis Vitorio Cargnini wrote:
> just one additional and if I have:
> vector< vector<double> > x;
> How to use the MPI_Send
> MPI_Send(&x[0][0], x[0].size(),MPI_DOUBLE, 2, 0, MPI_COMM_WORLD);
> ?


   The standard provides no information on where the different parts of
the data will be, relative to each other. In specific, there is no
reason to believe that the data in the different internally nested
doubles will be contiguous. (In fact, I know of no platform where it
will be.) That means trying to send the whole structure at once is

   What you wrote will provide a pointer to the first element of the
first nested vector to MPI_Send, and the length of that nested vector.
If that is what you intend, I expect it to work. (I have not tested it,
so I may be misthinking something here.) The other nested vectors could
be sent for themselves, using separate MPI_Send calls.

   The only reliable way to send all of the data at once would be to
serialize it off to a single vector or array for the send, then repack
it in the structure after it is received.