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>