【发布时间】:2012-10-29 17:06:33
【问题描述】:
我有类似的东西:
if (rank == winner) {
ballPos[0] = rand() % 128;
ballPos[1] = rand() % 64;
cout << "new ball pos: " << ballPos[0] << " " << ballPos[1] << endl;
MPI_Send(&ballPos, 2, MPI_INT, FIELD, NEW_BALL_POS_TAG, MPI_COMM_WORLD);
} else if (rank == FIELD) {
MPI_Recv(&ballPos, 2, MPI_INT, winner, NEW_BALL_POS_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
cout << "2 new ball pos: " << ballPos[0] << " " << ballPos[1] << endl;
}
但我在控制台中看到:
new ball pos: 28 59
2 new ball pos: 28 59
为什么cout 在接收之后打印在发送之前?
【问题讨论】:
-
您确定先发送再接收吗?通话是否被阻塞?
-
我看不出问题出在哪里。
rank == winner首先是true,然后rank == FIELD是true。这不正确吗? -
@PeterWood,
FIELD是一个常数 0,winner是从 1 到 5。所以它们是不同的。还是我误会了你? -
@RedX,我认为 Send, Recv 应该被阻止。它的 ISend 和 IRecv 没有阻塞?