我正在学习MPI_Send,但我对这种方法感到困惑。我写了一个简单的pingpong程序,rank-0节点将消息发送到rank-1节点,然后后者将消息返回给前者。
if (rank == 0) { /* Send Ping, Receive Pong */
dest = 2;
source = 2;
rc = MPI_Send(pingmsg, strlen(pingmsg)+1, MPI_CHAR, dest, tag, MPI_COMM_WORLD);
rc = MPI_Recv(buff, strlen(pongmsg)+1, MPI_CHAR, source, tag, MPI_COMM_WORLD, &Stat);
printf("Rank0 Sent: %s & Received: %s\n", pingmsg, buff);
}
else if (rank == 2) { /* Receive Ping, Send Pong */
dest = 0;
source = 0;
rc = MPI_Recv(buff, strlen(pingmsg)+1, MPI_CHAR, source, tag, MPI_COMM_WORLD, &Stat);
printf("Rank1 received: %s & Sending: %s\n", buff, pongmsg);
rc = MPI_Send(pongmsg, strlen(pongmsg)+1, MPI_CHAR, dest, tag, MPI_COMM_WORLD);
}
我在3节点环境中运行此程序。但是,系统显示:
Fatal error in MPI_Send: Other MPI error, error stack:
MPI_Send(173)..............: MPI_Send(buf=0xbffffb90, count=10, MPI_CHAR, dest=2, tag=1, MPI_COMM_WORLD) failed
MPID_nem_tcp_connpoll(1811): Communication error with rank 2: Unknown error 4294967295
我想知道为什么我可以从rank-0节点向rank-1节点发送消息,但是当从rank-0节点更改为rank-1节点时会发生错误?感谢。
答案 0 :(得分:0)
实际上你已经检查过MPI_SEND和MPI_RECV中的strlen(pingmsg)是否相同
使用MPI_SEND发送的数据量应小于或等于MPI_RECV要接收的数据量,否则会导致错误。