Я пытаюсь синхронизировать свои процессы в начале выполнения через 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