我正在处理发送/接收MPI程序,由于某种原因,该循环仅迭代一次,然后退出。有谁知道为什么吗?
代码:
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int rank;
int b2, a1;
MPI_Status status;
MPI_Init(NULL, NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
for (int j = 0; j < 100; j++) {
if (rank == 0) {
a1 = 10;
MPI_Sendrecv(&a1, 1, MPI_INT, 1, 99,
&b2, 1, MPI_INT, 1, 99,
MPI_COMM_WORLD, MPI_STATUS_IGNORE);
} else {
a1 = 20;
MPI_Sendrecv(&a1, 1, MPI_INT, 0, 99,
&b2, 1, MPI_INT, 0, 99,
MPI_COMM_WORLD, MPI_STATUS_IGNORE);
}
}
printf("Process %d: received %d\n", rank, b2);
MPI_Finalize();
}
输出(这应该重复多次,但这就是我所得到的):
Process 1: received 10
Process 0: received 20
答案 0 :(得分:2)
您的printf()
不在循环中。只打印一次也就不足为奇了。