【发布时间】:2020-01-30 09:33:48
【问题描述】:
我试图在执行开始时通过 MPI_Barrier 同步我的进程,但我的程序被阻止了。尽管如此,我看到所有进程都通过在上一条指令中的屏幕上打印来到达该行。
int num_processes, packet_size, partner_rank;
double start_comm_time, end_comm_time, comm_time;
comm_time = 0;
if(argc==3) {
if (sscanf (argv[1], "%i", &num_processes) != 1) {
fprintf(stderr, "error - parameter 1 not an integer");
} else;
if (sscanf (argv[2], "%i", &packet_size) != 1) {
fprintf(stderr, "error - parameter 2 not an integer");
} else;
}
else {
printf("\n Usage: broadcast $count $packet_size");
return 0;
}
char buf_send[packet_size], buf_recv[packet_size];
buf_send[0] = 0;
// Initialize
MPI_Init(NULL, NULL);
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
printf("\n Comm size %d \n", world_size);
printf("\n Process %d before barrier \n", world_rank);
// Time MPI_Bcast
MPI_Barrier(MPI_COMM_WORLD);
printf("\n Process %d after barrier \n", world_rank);
start_comm_time = MPI_Wtime();
MPI_Bcast(buf_send, packet_size, MPI_CHAR, 0, MPI_COMM_WORLD);
printf("\n Process %d before second barrier \n", world_rank);
MPI_Barrier(MPI_COMM_WORLD);
end_comm_time = MPI_Wtime();
这是我在打印输出中得到的:
Comm size 6
Process 0 before barrier
Comm size 6
Process 2 before barrier
Comm size 6
Process 3 before barrier
Comm size 6
Process 1 before barrier
Comm size 6
Process 4 before barrier
Comm size 6
Process 5 before barrier
【问题讨论】:
-
您的程序没有问题。罪魁祸首可能是您的 mpi 安装。
标签: mpi