Thanks Rajeev and tan.<div>I think I can write some code like tan suggested and see how the implementation behaves.</div><div><br></div><div>sam<br><br><div class="gmail_quote">On Wed, Aug 19, 2009 at 2:55 AM, Rajeev Thakur <span dir="ltr"><<a href="mailto:thakur@mcs.anl.gov">thakur@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>
<div dir="ltr" align="left"><span><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><font color="#0000ff" size="2" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span><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" align="left">
<hr>
<font size="2" face="Tahoma"><b>From:</b> <a href="mailto:mpich-discuss-bounces@mcs.anl.gov" target="_blank">mpich-discuss-bounces@mcs.anl.gov</a>
[mailto:<a href="mailto:mpich-discuss-bounces@mcs.anl.gov" target="_blank">mpich-discuss-bounces@mcs.anl.gov</a>] <b>On Behalf Of </b>chong
tan<br><b>Sent:</b> Tuesday, August 18, 2009 8:20 PM<div class="im"><br><b>To:</b>
<a href="mailto:mpich-discuss@mcs.anl.gov" target="_blank">mpich-discuss@mcs.anl.gov</a><br></div><b>Subject:</b> Re: [mpich-discuss] a question
about MPI_Send & MPI_Recv<br></font><br></div><div><div></div><div class="h5">
<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
<<a href="mailto:wl8150@googlemail.com" target="_blank">wl8150@googlemail.com</a>><br><b><span style="font-weight:bold">To:</span></b> <a href="mailto:mpich-discuss@mcs.anl.gov" target="_blank">mpich-discuss@mcs.anl.gov</a><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></div></div></blockquote></div>
</blockquote></div><br></div>