Write a code that using point to point communications performs a circular send/receive as represented in the following figure
Each task will declare two float arrays, A and B, of a fixed dimension (10000). Every element of 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. Each process sends only to the process on its right and receives only from the process on its left. As you can see from the picture the last process will send its array A to the first task.
Avoid deadlocks and make sure that the code will work with a general number of tasks. Therefore, you need two variables to be used as destination and source for the send and receive calls, inizialized as:
right = |
| my_rank + 1 | |
every task except the last
last task |
left = |
| my_rank - 1 | |
every task except the first
first task |
The program terminates with each process printing out one element of the array B.
I am task 0 and I have received b(0) = 3.00 I am task 1 and I have received b(0) = 0.00 I am task 2 and I have received b(0) = 1.00 I am task 3 and I have received b(0) = 2.00
HINTS: |
|
C |
|
MPI_ISEND |
|
MPI_RECV |
|
MPI_INIT |
|
MPI_COMM_SIZE | |
MPI_COMM_RANK |
|
MPI_FINALIZE |
|
|
|
MPI_ISEND |
|
MPI_RECV |
|
MPI_INIT |
|
MPI_COMM_SIZE |
MPI_COMM_SIZE(COMM, SIZE, IERROR) |
MPI_COMM_RANK |
MPI_COMM_RANK(COMM, RANK, IERROR) |
MPI_FINALIZE |