Question: Parallel Computing Lab Assignment - 2 ( marks = 1 0 ) 1 . Modify the program that just prints a line of output from

Parallel Computing Lab Assignment -2(marks =10)
1. Modify the program that just prints a line of output from each process (mpi
output.c) so that the output is printed in process rank order: process 0s
output first, then process 1s, and so on.
a. Use point-to-point communication.
b. Use collective communication such as gather.
Copy the source code in your answers file. Launch the Command line and
take a Screenshot of the window with the result of the program
execution including your name. (copy the Screenshot in your answers
file). Also, provide an explanation showing how the code works.
[3 marks]
2. What is deadlock in MPI? Explain one scenario showing a Source of
Deadlocks in MPI send and receive functions with sample code?
[1 mark]
3. Ring Problem
Write a C program that implements a ring algorithm using MPI. The
program calculates the sum of all the processs ranks.
The program steps are as follows:
1. All processes initialize MPI.
2. Each process gets its rank and the total number of processes.
3. Each process calculates its left and right neighbours. (For example, for
processor 3 its left is equal to 2 and its right is equal to 4).
4. Each process initially sends its rank to its right neighbour and receives the
rank of its left neighbour and initialize the sum variable to its rank.
5. Then, repeatedly do the following:
/* File: mpi_output.c
* Purpose: A program in which multiple MPI processes try to print a message.
* Section 3.3.1(pp.97-99.)
*/
#include
#include
int main(void){
int my_rank, comm_sz;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
printf("Proc %d of %d > Does anyone have a toothpick?
", my_rank, comm_sz);
MPI_Finalize();
return 0;
}/* main */
a. Each process adds the received value from its left neighbour to its
sum variable.
b. Send the received value from the left neighbour to its right
neighbour.
c. Receive a value from its left neighbour.
6. Steps in point 5 are repeated until each process receives its own rank.
7. Each process prints its rank and sum to the console.
8. All processes finalize MPI.
Copy the source code in your answers file. Launch the Command line and
take a Screenshot of the window with the result of the program execution
including your name. (copy the Screenshot in your answers file). Also, provide
an explanation showing how the code works. [3 marks]
4. Ping-Pong Problem
Write a MPI program to implement a ping-pong between two processes.
The number of ping-pong is given by the user. The program steps are as
follows:
1. Initialize MPI.
2. Get the rank and size of the communicator.
3. Check if the number of processes is equal to 2.
4. Get the number of ping-pong exchanges from the user.
5. Start the ping-pong communication loop (Initially ping-pong count =0) :
If the rank is 0, send the ping-pong count to rank 1 and receive the
ping-pong count from rank 1.
If the rank is 1, receive the ping-pong count from rank 0 and send the
ping-pong count to rank 0.
Increment the ping-pong count.
6. Repeat step 5 until the ping-pong count is equal to the number of pingpong exchanges.
7. Finalize MPI.
Copy the source code in your answers file. Launch the Command line and
take a Screenshot of the window with the result of the program execution
including your name. (copy the Screenshot in your answers file). Also, provide
an explanation showing how the code works. [3 marks]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!