Behavior of MPI_Send and MPI_Recv

前端 未结 1 1803
情书的邮戳
情书的邮戳 2021-01-26 00:29

Why these lines of code:

if(my_rank != 0) {
    sprintf(msg, \"Hello from %d of %d...\", my_rank, comm_sz);
    if(my_rank == 2) {
        sleep(2);
        spri         


        
相关标签:
1条回答
  • 2021-01-26 01:11

    strlen() does not include the null terminator, hence it will not be sent to the master. Receiving the message from rank 3 will not overwrite the later part of the string, so it is still displayed. You should use strlen(msg) + 1 as send count.

    0 讨论(0)
提交回复
热议问题