<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<STYLE type=text/css>DIV {
        MARGIN: 0px
}
</STYLE>
<META name=GENERATOR content="MSHTML 8.00.6001.18812"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=938005501-19082009><FONT color=#0000ff
size=2 face=Arial>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.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=938005501-19082009><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=938005501-19082009><FONT color=#0000ff
size=2 face=Arial>Rajeev</FONT></SPAN></DIV><BR>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> mpich-discuss-bounces@mcs.anl.gov
[mailto:mpich-discuss-bounces@mcs.anl.gov] <B>On Behalf Of </B>chong
tan<BR><B>Sent:</B> Tuesday, August 18, 2009 8:20 PM<BR><B>To:</B>
mpich-discuss@mcs.anl.gov<BR><B>Subject:</B> Re: [mpich-discuss] a question
about MPI_Send & MPI_Recv<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV
style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt">
<DIV>I will try to answer this before the real MPICH gurus jump in.</DIV>
<DIV> </DIV>
<DIV>First, MPI_Send() may not be truely blocked, it could be buffered.
So, we can't count on</DIV>
<DIV>it being truely blocked for our algorithm to work.</DIV>
<DIV> </DIV>
<DIV>secondly, when calling MPI_Send, the 2nd param is the size of the message
to be sent. THis</DIV>
<DIV>should be the intented size, or anything if your algorithm has a
bug. The MPI_Recv() call </DIV>
<DIV>actually do not know the size of the incoming message, the size you
specify here is the maximum</DIV>
<DIV>size your buffer allow. In your case, size is the size of the var
'message'.</DIV>
<DIV> </DIV>
<DIV>One experiment you can try is to create a second var like :</DIV>
<DIV> </DIV>
<DIV>char recvBuf[20] ;</DIV>
<DIV> </DIV>
<DIV>and have the sender send in long messages, say 100 bytes. Then have
the reciever do:</DIV>
<DIV> </DIV>
<DIV> MPI_Recv( recvBuf, 100, ... )</DIV>
<DIV> </DIV>
<DIV>and see what happen.</DIV>
<DIV> </DIV>
<DIV>tan</DIV>
<DIV><BR> </DIV>
<DIV
style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><BR>
<DIV
style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><FONT
size=2 face=Tahoma>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> samantha lin
<wl8150@googlemail.com><BR><B><SPAN
style="FONT-WEIGHT: bold">To:</SPAN></B> mpich-discuss@mcs.anl.gov<BR><B><SPAN
style="FONT-WEIGHT: bold">Sent:</SPAN></B> Tuesday, August 18, 2009 4:10:30
PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> [mpich-discuss] a
question about MPI_Send & MPI_Recv<BR></FONT><BR>Hi,
<DIV><BR></DIV>
<DIV>I got a simple example program from a book, PPMPI. The purpose of the
program:</DIV>
<DIV>
<DIV>Send a message from all processes with rank != 0 to process
0. Process 0 prints the messages received.</DIV></DIV>
<DIV><BR></DIV>
<DIV>The code is basically like the following:</DIV>
<DIV><BR></DIV>
<DIV>
<DIV>int main(int argc, char* argv[])</DIV>
<DIV>{</DIV>
<DIV>....</DIV>
<DIV>char message[100]; /* storage for
message */</DIV>
<DIV>...</DIV>
<DIV>
<DIV> if (my_rank != 0) {</DIV>
<DIV> /* Create message */</DIV>
<DIV> sprintf(message, "Greetings from process
%d!",</DIV>
<DIV> my_rank);</DIV>
<DIV> printf("len = %d\n",
strlen(message));</DIV>
<DIV> dest = 0;</DIV>
<DIV> /* Use strlen+1 so that '\0' gets
transmitted */</DIV>
<DIV> MPI_Send(message, strlen(message)+1,
MPI_CHAR, dest, tag, MPI_COMM_WORLD);</DIV>
<DIV> } else { /* my_rank == 0 */</DIV>
<DIV> for (source = 1; source < p;
source++) {</DIV>
<DIV> MPI_Recv(message, 100,
MPI_CHAR, source, tag, MPI_COMM_WORLD, &status);</DIV>
<DIV> printf("%s\n",
message);</DIV>
<DIV> }</DIV>
<DIV> }</DIV></DIV>
<DIV>...</DIV>
<DIV>}</DIV>
<DIV><BR></DIV>
<DIV>The program can compile and run successfully. </DIV>
<DIV>But count size of sent message, strlen(message)+1, is somehow different
from that of received message,100.</DIV>
<DIV>As this is synchronous send and receive, the receiver is supposed to wait
until it receives enough data.</DIV>
<DIV>Does anyone know how this is implemented in MPI? Or I
misunderstand the functions?</DIV>
<DIV><BR></DIV>
<DIV>Sam</DIV>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV><BR></DIV></DIV></DIV></DIV></DIV><BR></BLOCKQUOTE></BODY></HTML>