Question
Complete MPI program 1 to perform the necessary error checking for our previous example (MPI program 2) to ensure that two processes are required for
Complete MPI program 1 to perform the necessary error checking for our previous example (MPI program 2) to ensure that two processes are required for running the program. Program 1 (to complete): #include
int main(int argc, char* argv[]) { int my_rank, comm_sz; int token = 1; MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if ( ) { if (my_rank == 0)
fprintf(stderr, " ");
MPI_Finalize();
return 0; }
if(my_rank == 0) { MPI_Send(&token, 1, MPI_INT, 1, 0, MPI_COMM_WORLD); printf(" Process %d sent token %d to process 1. ", my_rank, token); }
else { MPI_Recv(&token, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("Process %d received token %d from process 0. ", my_rank, token); }
MPI_Finalize();
return 0; } Program 2 (Program we are checking for errors):
include
int main(void) { int my_rank, comm_sz; int token = 1; MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if(my_rank == 0) { MPI_Send(&token, 1, MPI_INT, 1, 0, MPI_COMM_WORLD); printf("Process %d sent token %d to process 1 ", my_rank, token); }
else { MPI_Recv(&token, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("Process %d received token %d from process 0 ", my_rank, token); }
MPI_Finalize();
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started