<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><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>
</body></html>