Title: Parallel Programming
1Parallel Programming
- Jonathan Hauenstein
- CAM mini-course
- University of Notre Dame
- May 8, 2008
2MPI
- MPI_Abort
- immediately terminate MPI program
- int MPI_Abort(MPI_Comm comm, int errorCode)
- Fortran
- MPI_ABORT(COMM, ERRORCODE, IERROR) INTEGER
COMM, ERRORCODE, IERROR - Note After any unusual termination of your
program, you should always make sure that all of
the processes have been successfully stopped
3MPI
4MPI
- Error if count for receiving is not large
enough to hold the message.
5Monte Carlo Approximation
- Approximate using Monte Carlo method
- Randomly select test points in the square -1,1
x -1,1 and determine if they lie in the unit
circle - is approximated as
- (area of -1,1 x -1,1) (proportion of test
points that lie in the unit circle)
6Monte Carlo Approximation
7Monte Carlo Approximation
8Monte Carlo Approximation
9Packing and Unpacking
- MPI can pack data into a single contiguous
buffer - input data can be of any datatype
- output buffer should be contiguous memory
- int MPI_Pack(void in, int inCount, MPI_Datatype
datatype, void out, int outSize, int position,
MPI_Comm comm) - MPI_PACK(INBUF, INCOUNT, DATATYPE, OUTBUF,
OUTSIZE, POSITION, COMM, IERROR)lttypegt
INBUF(), OUTBUF()INTEGER INCOUNT, DATATYPE,
OUTSIZE, POSITION, COMM, IERROR
10Packing and Unpacking
- Using MPI_PACKED datatype, the data can be
transmitted - MPI can unpack data from a single contiguous
buffer - int MPI_Unpack(void in, int inSize, int
position, void out, int outCount, MPI_Datatype
datatype, MPI_Comm comm) - MPI_UNPACK(INBUF, INSIZE, POSITION, OUTBUF,
OUTCOUNT, DATATYPE, COMM, IERROR)lttypegt
INBUF(), OUTBUF()INTEGER INSIZE, POSITION,
OUTCOUNT, DATATYPE, COMM, IERROR
11Packing and Unpacking
12Packing and Unpacking
- MPI_Pack_size can be used to calculate how much
memory to allocate for the output buffer - provides an upper bound on how much memory is
needed - int MPI_Pack_size(int count, MPI_Datatype
datatype, MPI_Comm comm, int size) - MPI_PACK_SIZE(INCOUNT, DATATYPE, COMM, SIZE,
IERROR)INTEGER INCOUNT, DATATYPE, COMM, SIZE,
IERROR
13Packing and Unpacking
14Create new datatypes
- Users can define there own datatypes
- using a user-defined datatype is more efficient
than repeated packing and unpacking of data - creating a MPI_Datatype is a 3 step process
- Setup the structures that define the datatype
- Build the MPI struct
- Commit the datatype
- user-defined datatypes should be cleared after it
is no longer needed
15Create new datatypes
- Step 1 Setup the structures that define the
datatype - The 3 structures define a datatype are
- blockLen number of elements in each block int
- indices byte displacement of each block
MPI_Aint - pointer arithmetic
- MPI_Address(void loc, MPI_Aint address) can be
used to find the address of loc. - types datatype of each block MPI_Datatype
16Create new datatypes
Step 2 Build the MPI struct int
MPI_Type_struct(int count, int blockLen,
MPI_Aint indices, MPI_Datatype types,
MPI_Datatype new_type) MPI_TYPE_STRUCT(COUNT,
BLOCKLEN, INDICES, TYPES, NEWTYPE, IERROR)
INTEGER COUNT, NEWTYPE, IERROR INTEGER
BLOCKLEN(), INDICES(), TYPES()
17Create new datatypes
Step 3 Commit the datatype int
MPI_Type_commit(MPI_Datatype new_type) MPI_TYP
E_COMMIT(DATATYPE, IERROR) INTEGER DATATYPE,
IERROR
18Create new datatypes
Clearing a user-defined datatype after it is no
longer needed int MPI_Type_free(MPI_Datatype
new_type) MPI_TYPE_FREE(DATATYPE,
IERROR) INTEGER DATATYPE, IERROR
19Create new datatypes
20Create new datatypes
21Trapezoid Rule
Approximate using trapezoid rule for
integration
Trapezoid rule
22Trapezoid Rule
23Trapezoid Rule
24Trapezoid Rule
25Trapezoid Rule
26mpirun
- Command line arguments for mpirun can be used to
- specify the number of processes to use
- specify which machines to use and how many
processes should be put on each of the machines - specify whether to run a process locally
- testing option to see where the processes will
be located - more advanced options allow for different
programs to be run on different architectures if
you have a heterogeneous system
27mpirun
- A machine file
- lists the machines you want to utilize
- contains the number of processes to put onto
each machine (optional) - Processes are placed on the machines in the order
they appear in the file. - If more processes are requested than listed in
the machine file, it cycles back to the top of
the file.
28mpirun
An example of a machine file
29mpirun
To utilize a machine file mpirun machinefile
ltname_of_filegt
To see the location of the processes, without
running the actual program, utilize the t
option mpirun machinefile ltname_of_filegt t
30mpirun
Example
31mpirun
To not put a process on the local machine, use
the nolocal option. mpirun nolocal Example
32Jumpshot
Jumpshot is a Java-based visualization program
used to create a picture so that you can analyze
your parallel code. It uses log files to create
its graphical representation.
To have MPI create the log files mpicc mpilog
33Jumpshot
Creating log file
34Jumpshot
Converting clog to slog2
35Jumpshot
Running jumpshot
36Jumpshot
- Instead of using a static distribution for
trapezoid rule, consider using a dynamic
distribution of the work - 1 head and n 1 compute processes
- trapezoids are distributed 100,000 at a time
37Jumpshot
Compute portion of trapezoidMPI_dyn.c
38Jumpshot
Control portion of trapezoidMPI_dyn.c
39Jumpshot
Running jumpshot
40Thank You!!!
All slides and example files are available
at http//www.nd.edu/jhauenst/parallelcourse