Professional Documents
Culture Documents
Lab Assesment 6 Parallel & Distributed Computing (L31+32) : Code
Lab Assesment 6 Parallel & Distributed Computing (L31+32) : Code
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.
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.
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.