MCSE-011 IGNOU STUDY MATERIAL

Page 115

Now, we shall illustrate use of these functions with an example.

PRAM Algorithms

Example 1: #include <mpi.h> int main(int argc, char **argv) { int i, tmp, sum, s, r, N, x[100]; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &s); MPI_Comm_rank(MPI_COMM_WORLD, &r); If(r==0) { printf( “Enter N:”); scanf (“%d”, &N); for (i=1; i<s; i++) MPI_Send(&N, 1, MPI_INT,i, i, MPI_COMM_WORLD); for (i=r, i<N; i=i+s) sum+= x[i]; for (i=r, i<s; i++) { MPI_Recv(&tmp, 1, MPI_INT,i, i, MPI_COMM_WORLD, &status); Sum+=tmp; } printf( “%d”, sum); } else { MPI_Recv(&N, 1, MPI_INT,0, i, MPI_COMM_WORLD, &status); for (i=r, i<N; i=i+s) sum+= x[i]; MPI_Send(&sum, 1, MPI_INT, 0, i, MPI_COMM_WORLD); } MPI_Finalize( ); } Merits of MPI Runs on either shared or distributed memory architectures; Can be used on a wider range of problems than OpenMP; Each process has its own local variables; and Distributed memory computers are less expensive than large shared memory computers. Drawbacks of MPI Requires more programming changes to go from serial to parallel version. Can be harder to debug, and Performance is limited by the communication network between the nodes. Parallel Virtual Machine (PVM) PVM (Parallel Virtual Machine) is a portable message-passing programming system, designed to link separate heterogeneous host machines to form a “virtual machine” which is a single, manageable parallel computing resource. Large computational problems such

31


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.