Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions