You create a Microsoft Message Passing Interface (MPI) application by using Microsoft Visual C++.
You write the following code segment. (Line numbers are included for reference only.)
01 MPI_Init(&argc, &argv);
02 int a[100], b[100], c[100], myrank;
03 MPI_Status status;
04 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
05 if (myrank==0)
06 {
07 MPI_Send(a, 100, MPI_INT, 1, 1, MPI_COMM_WORLD); 08 MPI_Send(b, 100, MPI_INT, 1, 2, MPI_COMM_WORLD); 09 }
10 else
11 {
12 MPI_Recv(b, 10, MPI_INT, 0, 2, MPI_COMM_WORLD,&status);
13 MPI_Recv(a, 10, MPI_INT, 0, 1, MPI_COMM_WORLD,&status); 14 }
The code segment will be executed with two MPI ranks. You discover that a deadlock occurs occasionally. You need to resolve deadlocks in the application. Which code segment should you use to replace lines 12 and 13? (Each correct answer presents a complete solution. Choose two.)
A.
MPI_Recv(a, 10, MPI_INT, 0, 1, MPI_COMM_WORLD,&status); MPI_Recv(b, 10, MPI_INT, 0, 2, MPI_COMM_WORLD,&status);
B.
MPI_Recv(b, 10, MPI_INT, 0, 2, MPI_COMM_WORLD,&status); MPI_Barrier(MPI_COMM_WORLD);
MPI_Recv(a, 10, MPI_INT, 0, 1, MPI_COMM_WORLD,&status);
C.
MPI_Request req;
MPI_Recv(b, 10, MPI_INT, 0, 1, MPI_COMM_WORLD,&status); MPI_Irecv(a, 10, MPI_INT, 0, 2, MPI_COMM_WORLD,&req);
D.
MPI_Request req;
MPI_Irecv(b, 10, MPI_INT, 0, 1, MPI_COMM_WORLD,&req); MPI_Recv(a, 10, MPI_INT, 0, 2, MPI_COMM_WORLD,&status);