[mpich-discuss] a question about MPI_Send & MPI_Recv
Rajeev Thakur
thakur at mcs.anl.gov
Tue Aug 18 20:55:56 CDT 2009
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/20090818/a95d7f64/attachment.htm>
More information about the mpich-discuss
mailing list