[mpich-discuss] a question about MPI_Send & MPI_Recv

samantha lin wl8150 at googlemail.com
Wed Aug 19 13:49:03 CDT 2009


Thanks Rajeev and tan.I think I can write some code like tan suggested and
see how the implementation behaves.

sam

On Wed, Aug 19, 2009 at 2:55 AM, Rajeev Thakur <thakur at mcs.anl.gov> wrote:

>  In MPI, you are allowed to post a receive of size larger than the
> matching send. Only the amount actually sent will be received and can be
> queried from the status object.
>
> Rajeev
>
>  ------------------------------
> *From:* mpich-discuss-bounces at mcs.anl.gov [mailto:
> mpich-discuss-bounces at mcs.anl.gov] *On Behalf Of *chong tan
> *Sent:* Tuesday, August 18, 2009 8:20 PM
> *To:* mpich-discuss at mcs.anl.gov
> *Subject:* Re: [mpich-discuss] a question about MPI_Send & MPI_Recv
>
>  I will try to answer this before the real MPICH gurus jump in.
>
> First, MPI_Send() may not be truely blocked, it could be buffered.  So, we
> can't count on
> it being truely blocked for our algorithm to work.
>
> secondly, when calling MPI_Send, the 2nd param is the size of the message
> to be sent.  THis
> should be the intented size, or anything if your algorithm has a bug.  The
> MPI_Recv() call
> actually do not know the size of the incoming message, the size you specify
> here is the maximum
> size your buffer allow.  In your case, size is the size of the var
> 'message'.
>
> One experiment you can try is to create a second var like :
>
> char    recvBuf[20] ;
>
> and have the sender send in long messages, say 100 bytes.  Then have the
> reciever do:
>
>   MPI_Recv( recvBuf, 100, ... )
>
> and see what happen.
>
> tan
>
>
>
>  ------------------------------
> *From:* samantha lin <wl8150 at googlemail.com>
> *To:* mpich-discuss at mcs.anl.gov
> *Sent:* Tuesday, August 18, 2009 4:10:30 PM
> *Subject:* [mpich-discuss] a question about MPI_Send & MPI_Recv
>
> Hi,
> I got a simple example program from a book, PPMPI. The purpose of the
> program:
>  Send a message from all processes with rank != 0 to process 0. Process 0
> prints the messages received.
>
> The code is basically like the following:
>
>  int main(int argc, char* argv[])
> {
> ....
> char        message[100];  /* storage for message  */
> ...
>      if (my_rank != 0) {
>         /* Create message */
>         sprintf(message, "Greetings from process %d!",
>             my_rank);
>         printf("len = %d\n", strlen(message));
>         dest = 0;
>         /* Use strlen+1 so that '\0' gets transmitted */
>         MPI_Send(message, strlen(message)+1, MPI_CHAR, dest, tag,
> MPI_COMM_WORLD);
>     } else { /* my_rank == 0 */
>         for (source = 1; source < p; source++) {
>             MPI_Recv(message, 100, MPI_CHAR, source, tag, MPI_COMM_WORLD,
> &status);
>             printf("%s\n", message);
>         }
>     }
> ...
> }
>
> The program can compile and run successfully.
> But count size of sent message, strlen(message)+1, is somehow different
> from that of received message,100.
> As this is synchronous send and receive, the receiver is supposed to wait
> until it receives enough data.
> Does anyone know how this is implemented in MPI? Or I misunderstand the
> functions?
>
> Sam
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20090819/d3a45e5d/attachment.htm>


More information about the mpich-discuss mailing list