Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Dated: 21/09/2020 MUSKAN AGRAWAL

ASSESSMENT 6 18BCE0707

LAB ASSESMENT 6

PARALLEL
&
DISTRIBUTED COMPUTING
(L31+32)

Consider a suitable instance that has MPI routines to assign different tasks
to different processors. For example, parts of an input data set might be
divided and processed by different processors, or a finite difference grid
might be divided among the processors available. This means that the
code needs to identify processors. In this example, processors are
identified by rank - an integer from 0 to total number of processors.

1. Implement the logic using C

2. Build the code

3. Show the screenshots with proper justification.

CODE:

#include <stdio.h>
#include <mpi.h>
int main(int argc, char **argv)
{
int my_rank;
int size; MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("Hello world!\n");
printf("processor number %d\n size %d\n", my_rank,size);
MPI_Finalize();
}
Dated: 21/09/2020 MUSKAN AGRAWAL
ASSESSMENT 6 18BCE0707

CODE SNIPPET:

EXECUTION:
REMARKS:
1. MPI_COMM_RANK (comm, rank) - MPI_COMM_RANK returns the rank
of the calling process in the group associated with the communicator.

2. MPI_COMM_SIZE (comm, size) - MPI_COMM_SIZE returns in size the


number of processes in the group associated with the communicator.

3. In the above snippet, we see that “Hello World!” was printed on the screen
using 4 different processors in parallel, and the processor number rank
and size of each of them being listed.

You might also like