Docsity

Fundamentals - Parallel Processing - Lecture Slides, Slides of Parallel Computing and Programming

Partial preview of the text

Download Fundamentals - Parallel Processing - Lecture Slides and more Slides Parallel Computing and Programming in PDF only on Docsity!

MPI Fundamentals—A Quick

Overview

Intro by Example

Blocking Send’s and Receive’s

Blocking Send’s and Receive’s (contd.)

Blocking Send’s and Receive’s (contd.)

Blocking Send’s and Receive’s (contd.)

An example: MPI_Status status; MPI_Recv( ..., &status ); ... status.MPI_TAG; ... status.MPI_SOURCE; MPI_Get_count( &status, datatype, &count ); MPI_TAG and MPI_SOURCE primarily of use when MPI_ANY_TAG and/or MPI_ANY_SOURCE in the receive. MPI_Get_count may be used to determine how much data of a particular type was received.

Blocking Send’s and Receive’s (contd.)

Blocking Send’s and Receive’s (contd.)

Blocking Send’s and Receive’s (contd.)

Blocking Send’s and Receive’s (contd.)

Collective operations: An Example

#include "mpi.h“
#include <math.h>
int main(argc,argv)
int argc; char *argv[];
int done = 0, n, myid, numprocs, i, rc;
double PI25DT = 3.141592653589793238462643;
double mypi, pi, h, sum, x, a;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid);
while (!done)
{ if (myid == 0) { printf("Enter the number of intervals: (0 quits) "); scanf("%d",&n); }
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (n == 0) break;
h = 1.0 / (double) n; sum = 0.0;
for (i = myid + 1; i <= n; i += numprocs)
x = h * ((double)i - 0.5); sum += 4.0 / (1.0 + x*x);
mypi = h * sum;
MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
if (myid == 0) printf("pi is approximately %.16f, Error is %.16f\n", pi, fabs(pi - PI25DT));
MPI_Finalize();
Run either program for PI. Write new versions that replace the calls to MPI_Bcast and MPI_Reduce with
MPI_Send and MPI_Recv.