Can you help me solve the advanced version of this question
A set of processes are arranged in a ring.
Each process stores its rank in MPI_COMM_WORLD into an integer variable snd_buf.
Each process passes this on to its neighbor on the right.
Each processor calculates the sum of all values.
Keep passing it around the ring until the value is back where it started, i.e.
each process calculates sum of all ranks.
Use non-blocking MPI_Issend
– to avoid deadlocks
– to verify the correctness, because blocking synchronous send will cause a deadlock
here is my program
#include <stdio.h>
#include <mpi.h>
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
int snd_buf = rank;
int rcv_buf;
int total_sum = 0;
MPI_Request send_request, recv_request;
MPI_Status recv_status;
// Start the non-blocking send
MPI_Issend(&snd_buf, 1, MPI_INT, (rank + 1) % size, 0, MPI_COMM_WORLD, &send_request);
do {
MPI_Recv(&rcv_buf, 1, MPI_INT, (rank - 1 + size) % size, 0, MPI_COMM_WORLD, &recv_status);
total_sum += rcv_buf;
// Wait for the non-blocking send
MPI_Wait(&send_request, MPI_STATUS_IGNORE);
MPI_Issend(&rcv_buf, 1, MPI_INT, (rank + 1) % size, 0, MPI_COMM_WORLD, &send_request);
} while (rcv_buf != rank);
printf("Rank %d: Total Sum of Ranks = %d\n", rank, total_sum);
MPI_Finalize();
return 0;
}
I need help with the advanced version of it which is the following
Modify the pass-around-the-ring exercise.
Calculate two separate sums:
– rank integer sum (as before)
– rank floating point sum
Use a struct datatype for this
with same fixed memory layout for send and receive buffer.
use
int MPI_Type_struct(int count, int \*array_of_blocklengths, MPI_Aint \*array_of_displacements, MPI_Datatype \*array_of_types, MPI_Datatype \*newtype)
i am trying to use int MPI_Type_struct(int count, int \*array_of_blocklengths, MPI_Aint \*array_of_displacements, MPI_Datatype \*array_of_types, MPI_Datatype \*newtype)
but so far can not reach any results :(