Question: #include #include #include int main(int argc, char** argv) { int size, rank; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if(size != 3) { if(rank == 0)

#include #include #include int main(int argc, char** argv) { int size, rank; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if(size != 3) { if(rank == 0) { printf("This program needs to run on exactly 3 processes "); } } else { if(rank ==0){ int parcel; MPI_Recv(&parcel, 1, MPI_INT, 1, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("Received %d from process %d ", x, 1); int number = rank + 1; MPI_send(&parcel, 1, MPI_INT, 2, 2, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("Received %d from process %d ", y, 2); } else { if(rank == 1){ usleep(5000000); } } MPI_Finalize(); return 0; }

could you fix my code please I want to write a "Pass-the-parcel" MPI program that will run with 3 or more nodes, such that process rank 0 will send an integer variable call "parcel" initialised with 1, to Process rank 1 which will add 1 to the parcel and then send it to process rank 2, and so on until the highest rank process will send it back to Process rank 0, at which point the parcel variable should contain the value of the number of nodes there are above is my code but it doesn't run correctly.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Certainly The goal here is to implement a Passtheparcel program using MPI Message Passing Interface that will distribute and manipulate a variable par... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!