Write a code using point to point communication that makes two processes send each other an array of floats containing their rank. Each of the processes will declare two float arrays, A and B, of a fixed dimension (10000). All of the elements of the array A will be initialized with the rank of the process. Then, A and B will be used as the buffers for SEND and RECEIVE, respectively. The program terminates with each process printing out one element of the array B.
The program should follow this scheme:
The output should look like
I am task 0 and I have received b(0) = 1.00 I am task 1 and I have received b(0) = 0.00
HINTS: |
|
C |
|
MPI_SEND |
int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) |
MPI_RECV |
|
MPI_INIT |
|
MPI_COMM_SIZE | |
MPI_COMM_RANK |
|
MPI_FINALIZE |
|
|
|
MPI_SEND |
|
MPI_RECV |
|
MPI_INIT |
|
MPI_COMM_SIZE |
MPI_COMM_SIZE(COMM, SIZE, IERROR) |
MPI_COMM_RANK |
MPI_COMM_RANK(COMM, RANK, IERROR) |
MPI_FINALIZE |
QUESTIONS: |
Q- What happens if the order of the send/receive in task 1 is inverted? (answer) |
Q- Try to reduce the SEND buffer A to just one element and invert the order of send/receive in task 1. What happens when you run the code? (answer) |
Q- Rewrite the code without any IF statement and any deadlock. What do you need to use instead of the blocking SEND? (answer) |