Docsity

Collective Communications-Message Passing Interface Library-Lecture Slides, Slides of Microprocessor and Interfacing

Partial preview of the text

Download Collective Communications-Message Passing Interface Library-Lecture Slides and more Slides Microprocessor and Interfacing in PDF only on Docsity!

Dr. Hanif Durad^

2

Lecture Outline  Collective Communication  First Program using Collective communication  The Master- Slave Paradigm  Multiplying a matrix with a vector

IntroMPI.ppt

Another Approach to Parallelism  Collective routines provide a higher-level way toorganize a parallel program  Each process executes the same communicationoperations  MPI provides a rich set of collectiveoperations…

Dr. Hanif Durad^

IntroMPI.ppt^3

Collective Communication (1/2)  MPI_BCAST  MPI_SCATTER  MPI_SCATTERV  MPI_GATHER  MPI_GATHERV  MPI_ALLGATHER  MPI_ALLGATHERV  MPI_ALLTOALL

pp2003\lecture4.ppt

Dr. Hanif Durad

Collective Communication (2/2)  MPI_ALLTOALLV  MPI_REDUCE  MPI_ALLREDUCE  MPI_SCAN  MPI_REDUCE_SCATTER  MPI_OP_CREAT  MPI_BARRIER

pp2003\lecture4.ppt

Dr. Hanif Durad

Example of MPI_BCAST#include “mpi.h”int main( int argc, char* argv[] ){ int rank;int ibuf;MPI_Init( &argc, &argv );MPI_Comm_rank( MPI_COMM_WORLD, &rank );if(rank == 0) ibuf = 12345;else ibuf = 0;MPI_Bcast(&ibuf, 1, MPI_INTEGER, 0, MPI_COMM_WORLD);printf(“ibuf = %d\n”, ibuf);MPI_Finalize();}

bcast.c Dr. Hanif Durad

broadcast(data,…);^ source^ data

  • group members

Comm.ppt

Dr. Hanif Durad

Example of MPI_SCATTER ( 1/2)#include “mpi.h”int main( int argc, char* argv[] ){ int i;int rank, nproc;int isend[3], irecv;MPI_Init( &argc, &argv );MPI_Comm_size( MPI_COMM_WORLD, &nproc );MPI_Comm_rank( MPI_COMM_WORLD, &rank );if(rank == 0) {for(i=0; i<nproc; i++)isend(i) = i+1;}^

scatter.c Dr. Hanif Durad

Example of MPI_SCATTER ( 2/2)MPI_Scatter( isend, 1, MPI_INTEGER, irecv, 1, MPI_INTEGER, 0,MPI_COMM_WORLD);printf(“irecv = %d\n”, irecv);MPI_Finalize();}

Dr. Hanif Durad

MPI_SCATTERV^ ^ Usage^ ^ int MPI_Scatterv( void* sendbuf,

/* in /int sendcounts,^ /* in /int displs, /* in /MPI_Datatype sendtype,^ / in /void recvbuf,^ /* in /int recvcount, / in /MPI_Datatype recvtype,^ / in /int root, / in /MPI_Comm comm);^ / in */

^ Description^ ^ Distributes individual messages from root to each process incommunicator^ ^ Messages can have different sizes and displacements

Example ofMPI_SCATTERV(1/2)#include “mpi.h”int main( int argc, char* argv[] ){ int i;int rank, nproc;int iscnt[3] = {1,2,3}, irdisp[3] = {0,1,3};int isend[6] = {1,2,2,3,3,3}, irecv[3];MPI_Init( &argc, &argv );MPI_Comm_size( MPI_COMM_WORLD, &nproc );MPI_Comm_rank( MPI_COMM_WORLD, &rank );ircnt = rank + 1;

scatterv.c Dr. Hanif Durad

Dr. Hanif Durad

MPI_GATHER^ ^ Usage^ ^ int MPI_Gather( void* sendbuf,

/* in */ int sendcount,^

/* in */ MPI_Datatype sendtype,

/* in / void recvbuf,^

/* out */ int recvcount,^

/* in */ MPI_Datatype recvtype,

/* in */ int root,^

/* in */ MPI_Comm comm );

/* in */

^ Description^ ^ Collects individual messages from each process in communicatorto the root process and store them in rank order

Dr. Hanif Durad

Example of MPI_GATHER (2/2)if(rank == 0) {for(i=0; i<3; i++)printf(“irecv = %d\n”, irecv[i]);MPI_Finalize();}

Dr. Hanif Durad

gather(…)^ dest concatenationdual of scatter

Comm.ppt

  • group members