Title: COMP309/509 - Lecture 22
class: middle, center, inverse
COMP309/509 - Parallel and Distributed Computing
Lecture 22 - Advanced MPI
By Mitchell Welch
University of New England
Reading
- A users guide to MPI (This respurce is a bit dated, however the examples are still current)
man mpirun
- Assignment 4
- Project (COMP509)
Summary
- Advanced MPI Commumication
- Matrix Multiplication in MPI
Advanced MPI Commumication
- We have seen two forms of collective communication in MPI:
MPI_Bcast acts:
- like a send for the process whose rank is root.
- like a receive for all other processes.
Advanced MPI Commumication
MPI_Reduce acts:
- like a receive for the process whose rank is root.
- like a send for all other processes.
- the thing received is the accumulation of all the sends.
- it is accumulated using the binary operation
MPI_Op.
- Built-in MPI_Ops:
MPI_MAX MPI_MIN MPI_SUM MPI_PROD MPI_LAND MPI_LOR
Advanced MPI Commumication
- Thus these calls are a form of:
- communication.
- synchronization!.
- Similarly
MPI_Barrier can be thought of in the same light.
- Another example is
MPI_Gather
Advanced MPI Commumication
MPI_Gather acts:
- like a receive for the process whose rank is root.
- like a send for all processes, including root.
- the thing received is the accumulation of all the sends.
- it is accumulated via concatenation in the receive buffer, ordered by rank.
- Thus
MPI_Gather would be perfect for collecting the rows of the C matrix in the algorithm used in pvmmm!
Advanced MPI Commumication
#include "mpi.h"
int MPI_Gather (void *sndbuf, int sndcnt, MPI_Datatype sndtyp,
void *rcvbuf, int rcvcnt, MPI_Datatype rcvtyp,
int root, MPI_Comm comm )
- Gathers together values from a group of processes.
sndbuf is the address of send buffer.
sndcnt is the number of elements in send buffer.
Advanced MPI Commumication
sndtyp is the type of send buffer items.
rcvbuf is the address of receive buffer.
- significant only at root.
rcvcnt is the number of elements for any single receive
- significant only at root.
root is the rank of receiving process.
comm is the communicator of the processes participating in the gathering.
Advanced MPI Commumication
- Each process in the comm communicator:
sends the contents of sndbuf to the process with rank root.
- This includes the process with rank root.
- The process root concatenates the received data in process rank order in rcvbuff.
- That means:
- The data from process 0 comes first,
- Followed by the data from process 1,
- and so on
- all the way to the last process in the communicator comm.
Advanced MPI Commumication
- The
rcv arguments are only significant at the root process.
rcvcnt is the number of elements received from each particular process, not the total.
- Thus
rcvbuf should be capable of storing rcvcnt times the number of processes in the communicator.
Advanced MPI Commumication
#include "mpi.h"
int MPI_Scatter(void *sndbuf, int sndcnt, MPI_Datatype sndtyp,
void *rcvbuf, int rcvcnt, MPI_Datatype rcvtyp,
int root, MPI_Comm comm )
- Scatters the values to a group of processes.
Advanced MPI Commumication
sndbuf is the address of send buffer.
- significant only at root.
sndcnt is the number of elements in send buffer.
- significant only at root.
sndtype is the type of send buffer items.
rcvbuf is the address of receive buffer.
rcvcnt is the number of elements for any single receive
root is the rank of scattering process.
comm is the communicator of the processes participating in the scattering.
Advanced MPI Commumication
- Another procedure that would great for porting!
MPI_Scatter is the inverse operation to a gathering.
- The process with rank root distributes the contents of sndbuf among the processes in the communicator comm.
- The contents of the sndbuf are split into
nproc segments, each consisting of sndcnt items.
Advanced MPI Commumication
- Scattering means:
- process 0 gets the first segment.
- process 1 gets the second segment.
- and so on
- all the way to the last process in the communicator comm which gets the
nprocth segment.
- The
snd arguments are only significant at the root process.
- The
rcv arguments are significant at all processes.
Advanced MPI Commumication
- Lets use them to do matrix multiplication ring style.
- There are two versions of the program in the Examples subdirectory.
- mpimm.c contains oodles of error checking.
- abbreviated-mpimm.c contains no error checking.
- You should know by now that for good marks your solutions should look like the former not the latter!!
Matrix Multiplication in MPI
- Review the Examples
- mpimm.c
- abbreviated-mpimm.c
class: middle, center, inverse
Questions?
Reading
- A users guide to MPI (This respurce is a bit dated, however the examples are still current)
man mpirun
- Assignment 4
- Project (COMP509)