Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

It's too clear just run the program and answer these question Why does half the processes send before receiving and vice versa? What would happen

It's too clear just run the program and answer these question Why does half the processes send before receiving and vice versa? What would happen if all send before receiving?

------------------------------------------------------------------------------------------------------------------------ #include "mpi.h" #include #include #define MASTER 0

int main (int argc, char *argv[]) { int numtasks, taskid, len, partner, message; char hostname[MPI_MAX_PROCESSOR_NAME]; MPI_Status status;

MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &taskid); MPI_Comm_size(MPI_COMM_WORLD, &numtasks);

/* need an even number of tasks */ if (numtasks % 2 != 0) { if (taskid == MASTER) printf("Quitting. Need an even number of tasks: numtasks=%d ", numtasks); } else { if (taskid == MASTER) printf("MASTER: Number of MPI tasks is: %d ",numtasks);

MPI_Get_processor_name(hostname, &len); printf ("Hello from task %d on %s! ", taskid, hostname);

/* determine partner and then send/receive with partner */ if (taskid < numtasks/2) { partner = numtasks/2 + taskid; MPI_Send(&taskid, 1, MPI_INT, partner, 1, MPI_COMM_WORLD); MPI_Recv(&message, 1, MPI_INT, partner, 1, MPI_COMM_WORLD, &status); } else if (taskid >= numtasks/2) { partner = taskid - numtasks/2; MPI_Recv(&message, 1, MPI_INT, partner, 1, MPI_COMM_WORLD, &status); MPI_Send(&taskid, 1, MPI_INT, partner, 1, MPI_COMM_WORLD); }

/* print partner info and exit*/ printf("Task %d is partner with %d ",taskid,message); }

MPI_Finalize(); }

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

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

What is the meaning of the term opportunity recognition?

Answered: 1 week ago

Question

2. Place a value on the outcomes.

Answered: 1 week ago