Download CMSC 714: Lecture 3 - Message Passing with PVM and MPI - Prof. Alan L. Sussman and more Study notes Computer Science in PDF only on Docsity!
CMSC 714 - Alan Sussman and J.
CMSC 714
Lecture 3
Message Passing with
PVM and MPI
Alan Sussman
CMSC 714 โ Alan Sussman and J. Hollingsworth 2
Notes
To access papers in ACM or IEEE digital library,
must come from a UMD IP address
Accounts emailed soon for UMIACS bug cluster and
tau SUN SMP
First assignment probably announced on Tuesday
CMSC 714 - Alan Sussman and J.
CMSC 714 โ Alan Sussman and J. Hollingsworth 3
Last time
Coordination for parallel programs
- synchronization
- load balancing
Control vs. data parallelism
Metrics
- Speedup - vs. best known serial algorithm
- Scaled speedup
- Amdahlโs law
- Maximize computation to communication ratio
Writing parallel programs
- compiler converts old serial code
- serial langage plus communication library
- new programming language
- hybrid - old language with new constructs
CMSC 714 โ Alan Sussman and J. Hollingsworth 4
PVM
Provide a simple, free, portable parallel environment
Run on everything
- Parallel Hardware: SMP, MPPs, Vector Machines
- Network of Workstations: ATM, Ethernet,
- UNIX machines and PCs running Win32 API
- Works on a heterogenous collection of machines
- handles type conversion as needed
Provides two things
- message passing library
- point-to-point messages
- synchronization: barriers, reductions
- OS support
- process creation (pvm_spawn)
CMSC 714 - Alan Sussman and J.
CMSC 714 โ Alan Sussman and J. Hollingsworth 7
PVM Process Control
Creating a process
- pvm_spawn(task, argv, flag, where, ntask, tids)
- task is name of program to start
- flag and where provide control of where tasks are started
- ntask controls how many copies are started
- program must be installed on target machine
- returns number of tasks actually started
Ending a task
- pvm_exit
- does not exit the process, just the PVM machine
Info functions
- pvm_mytid() - get the process task id
CMSC 714 โ Alan Sussman and J. Hollingsworth 8
PVM Group Operations
Group is the unit of communication
- a collection of one or more processes
- processes join group with pvm_joingroup(โโ)
- each process in the group has a unique id
Barrier
- can involve a subset of the processes in the group
- pvm_barrier(โโ, count)
Reduction Operations
- pvm_reduce( void (*func)(), void *data, int count, int datatype, int msgtag, char *group, int rootinst)
- result is returned to rootinst node
- does not block
- pre-defined funcs: PvmMin, PvmMax,PvmSum,PvmProduct
CMSC 714 - Alan Sussman and J.
CMSC 714 โ Alan Sussman and J. Hollingsworth 9
PVM Performance Issues
Messages have to go through PVMD
- can use direct route option to prevent this problem
Packing messages
- semantics imply a copy
- extra function call to pack messages
Heterogenous Support
- information is sent in machine independent format
- has a short circuit option for known homogenous comm.
- passes data in native format then
CMSC 714 โ Alan Sussman and J. Hollingsworth 10
Sample PVM Program int main(int argc, char *argv) { int myGroupNum; int friendTid; int mytid; int tids[2]; int message[MESSAGESIZE]; int c,i,okSpawn; / Initialize process and spawn if necessary / myGroupNum=pvm_joingroup("ping-pong"); mytid=pvm_mytid(); if (myGroupNum==0) { / I am the first process / pvm_catchout(stdout); okSpawn=pvm_spawn(MYNAME,argv,0,"",1,&friendTid); if (okSpawn!=1) { printf("Can't spawn a copy of myself!\n"); pvm_exit(); exit(1); } tids[0]=mytid; tids[1]=friendTid; } else { /I am the second process */ friendTid=pvm_parent(); tids[0]=friendTid; tids[1]=mytid; } pvm_barrier("ping-pong",2);
if (myGroupNum==0) { /* Initialize the message / for (i=0 ; i<MESSAGESIZE ; i++) { message[i]='1'; } } / Now start passing the message back and forth */ for (i=0 ; i<ITERATIONS ; i++) { if (myGroupNum==0) { pvm_initsend(PvmDataDefault); pvm_pkint(message,MESSAGESIZE,1); pvm_send(friendTid,msgid); pvm_recv(friendTid,msgid); pvm_upkint(message,MESSAGESIZE,1); } else { pvm_recv(friendTid,msgid); pvm_upkint(message,MESSAGESIZE,1); pvm_initsend(PvmDataDefault); pvm_pkint(message,MESSAGESIZE,1); pvm_send(friendTid,msgid); } } pvm_exit(); exit(0); }
CMSC 714 - Alan Sussman and J.
CMSC 714 โ Alan Sussman and J. Hollingsworth 13
MPI Communicators
Provide a named set of processes for communication
- plus a context โ system allocated unique tag
All processes within a communicator can be named
Allows libraries to be constructed
- application creates communicators
- library uses it
- prevents problems with posting wildcard receives
- adds a communicator scope to each receive
All programs start with MPI_COMM_WORLD
- Functions for creating communicators from other communicators (split, duplicate, etc.)
- Functions for finding out about processes within communicator (size, my_rank, โฆ)
CMSC 714 โ Alan Sussman and J. Hollingsworth 14
Non-Blocking Point-to-point Functions
Two Parts
- post the operation
- wait for results
Also includes a poll/test option
- checks if the operation has finished
Semantics
- must not alter buffer while operation is pending (wait returns or test returns true)
- and data not valid for a receive until operation completes
CMSC 714 - Alan Sussman and J.
CMSC 714 โ Alan Sussman and J. Hollingsworth 15
Collective Communication
Communicator specifies process group to participate
Various operations, that may be optimized in an MPI
implementation
- Barrier synchronization
- Broadcast
- Gather/scatter (with one destination, or all in group)
- Reduction operations โ predefined and user-defined
- Also with one destination or all in group
- Scan โ prefix reductions
Collective operations may or may not synchronize
- Up to the implementation, so application canโt make assumptions
CMSC 714 โ Alan Sussman and J. Hollingsworth 16
MPI Calls
Include <mpi.h> in your C/C++ program
First call MPI_Init(&argc, &argv)
MPI_Comm_rank(MPI_COMM_WORLD, &myrank)
- myrank is set to id of this process (in range 0 to P-1)
MPI_Wtime()
At the end, call MPI_Finalize()
- No MPI calls allowed after this
CMSC 714 - Alan Sussman and J.
CMSC 714 โ Alan Sussman and J. Hollingsworth 19
Sample MPI Program #include โmpi.hโ int main(int argc, char *argv) { int myrank, friendRank; char message[MESSAGESIZE]; int i, tag=MSG_TAG; MPI_Status status; / Initialize, no spawning necessary / MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD,&myrank); if (myrank==0) { / I am the first process / friendRank = 1; } else { /I am the second process / friendRank=0; } MPI_Barrier(MPI_COMM_WORLD); if (myrank==0) { / Initialize the message */ for (i=0 ; i<MESSAGESIZE ; i++) { message[i]='1'; } }
/* Now start passing the message back and forth */ for (i=0 ; i<ITERATIONS ; i++) { if (myrank==0) { MPI_send(message, MESSAGESIZE, MPI_CHAR, friendRank, tag, MPI_COMM_WORLD); MPI_Recv(message, MESSAGESIZE, MPI_CHAR, friendRank, tag, MPI_COMM_WORLD, &status); } else { MPI_Recv(message, MESSAGESIZE, MPI_CHAR, friendRank,tag, MPI_COMM_WORLD, &status); MPI_send(message, MESSAGESIZE, MPI_CHAR, friendRank, tag, MPI_COMM_WORLD); } } MPI_Finalize(); exit(0); }
CMSC 714 โ Alan Sussman and J. Hollingsworth 20
For more details
PVM โ http://www.csm.ornl.gov/pvm/pvm_home.html
- current version is 3.4.5, available for download from netlib
- book from MIT Press is PVM: Parallel Virtual Machine A Users' Guide and Tutorial for Networked Parallel Computing
MPI โ http://www.mpi-forum.org
- includes both 1.1 and 2.0 documentation (API)
- books from MIT Press include Using MPI and MPI: The Complete Reference
- multiple public domain implementations available
- mpich โ Argonne National Lab
- OpenMPI (formerly LAM) โ http://www.open-mpi.org
- vendor implementations available too (IBM, Cray, Sun, โฆ)
- for UMIACS Linux cluster info, see http://www.umiacs.umd.edu/research/parallel/ - start with Class guide link โ youโll be using the bug cluster