LAM/MPI logo

LAM/MPI Development Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Brian Barrett (brbarret_at_[hidden])
Date: 2005-10-04 10:57:48


On Oct 4, 2005, at 10:45 AM, Alexandre Lemaire wrote:

> I have a basic usage question - running into a hurdle with C++.
>
> I have a series of int * arrays which I need to send in one to
> one communication between processors. These arrays are of varying
> sizes, so I can't guarantee a receive count on the receiving end
> (the MPI functions seem to require this..)
>
> How do I send and receive an array if integers?
>
> ex:
>
> int * arr = new int[X]; // X varies
> MPI::COMM_WORLD.Send(...
>
> // and then down on receiving end:
> ???

There are two ways to do this. If you know the upper bound on the
array size, you can pass the upper bound as the receive length (just
make sure you have that much space available to receive the
messages...). You can then use the MPI_STATUS information to
determine how much data was received. Remember that while it is an
error to receive into a buffer that is too small, it is perfectly
acceptable to receive into a buffer that is too big.

The second option is to send two messages - the first containing the
length of the second. This comes at some performance penalty, but
will work if you don't know the upper bound on array size.

Hope this helps,

Brian