Lab Mpi
Lab Mpi
2006 UC Regents!
1!
!processors run asynchronously: each processor has its own data and its own instructions!
"#
2006 UC Regents!
2!
Processes have separate address spaces! Processes communicate via sending and receiving messages!
!#
MPI is designed mainly for SPMD/MIMD (or distributed memory parallel supercomputer)!
"# "# "#
Each process is run on a separate node! Communication is over high-performance switch! Paragon, IBM SP2, Meiko CS-2, Thinking Machines CM-5, NCube-2, and Cray T3D! Multiple processes can read/write to the same memory location! SGI Onyx, Challenge, Power Challenge, Power Challenge Array, IBM SMP, Convex Exemplar, and the Sequent Symmetry! Sun, DEC, Hewlett-Packard, SGI, IBM, Intel and Pentium (various Linux OS)!
2006 UC Regents!
!#
!#
3!
What is MPI?!
!#
Message Passing application programmer Interface! "# Designed to provide access to parallel hardware!
# Clusters! # Heterogeneous networks! # Parallel computers!
Additional services!
# Environmental inquiry! # Basic timing info for measuring application performance! # Proling interface for external performance monitoring!
2006 UC Regents! 4!
MPI advantages!
!# Mature
"#
!# User
"#
interface:!
Efcient and simple (vs. PVM)! "# Buffer handling! "# Allow high-level abstractions!
!# Performance!
2006 UC Regents! 5!
MPI disadvantages!
!# MPI
!# Execution
MPI features!
!# !#
Modes of communication!
synchronous ready buffered
standard
"# "#
Structured buffers! Derived datatypes! Native built-in and user-dened collective operations! Data movement routines! Users can intercept MPI calls and call their own tools!
2006 UC Regents! 7!
!#
Collective communication!
"# "#
!#
Proling!
"#
Communication modes!
!#
standard!
"#
send has no guarantee that corresponding receive routine has started! send and receive can start before each other but complete together! used for accessing fast protocols! user guarantees that matching receive was posted! use with care!! send may start and return before matching receive! buffer space must be provided!
2006 UC Regents! 8!
!#
synchronous!
"#
!#
ready !
"# "# "#
!#
buffered!
"# "#
"#
!#
10!
MPI complexity!
!# MPI
MPI_Bcast MPI_Reduce
if:!
Your data do not t data parallel model! Need portable parallel program! Writing parallel library!
!# Don$t
!# !# !#
use if:!
Don$t need any parallelism ! Can use libraries! Can use fortran!
2006 UC Regents!
12!
#include mpi.h!
MPI!
mpicc -o prog prog.c ! -mpilog Generate log les of MPI calls! -mpitrace Trace execution of MPI calls! -mpianim Real-time animation of MPI (not available on all systems)! --help Find list of available options! get Makele.in template and create Makele! mpirecong Makele! compile! make progName!
2006 UC Regents! 14!
!#
Use makele!!
"#
"#
For mpich:!
# mpirun -np2 foo
For lam:!
# # # # # # lamboot -v lamhosts mpirun -v -np 2 foo lamclean -v ! mpirun ! lamclean ! lamhalt !
2006 UC Regents!
15!
2006 UC Regents!
16!
!#
!#
!# !#
!#
!#
! !
2006 UC Regents!
2006 UC Regents!
18!
2006 UC Regents!
19!
hello.c!
#include "mpi.h"! #include <stdio.h>! int main(int argc ,char *argv[])! {! !int myrank;! !MPI_Init(&argc, &argv);! !MPI_Comm_rank(MPI_COMM_WORLD, &myrank);! !fprintf(stdout, "Hello World, I am process %d\n", myrank);! !MPI_Finalize();! !return 0;! }!
2006 UC Regents!
20!
Example 1 (cont$d)!
5. compile!
$ mpicc -o hello hello.c! 6. create machines le with IP$s of two nodes. Use your numbers here!! 198.202.156.1! 198.202.156.2! 7. start LAM! $ lamboot -v machines ! 8. run your program! $ mpirun -np 2 -v hello ! 9. clean after the run! $ lamclean -v! 10. stop LAM! $ lamhalt !
2006 UC Regents!
21!
Example1 output!
$ ssh-agent $SHELL! $ ssh-add!
$ which mpicc! $ mpicc -o hello hello.c ! $ lamboot -v machines ! LAM 7.1.1/MPI 2 C++/ROMIO - Indiana University! n-1<27213> ssi:boot:base:linear: booting n0 (rocks-155.sdsc.edu)! n-1<27213> ssi:boot:base:linear: booting n1 (10.255.255.254)! n-1<27213> ssi:boot:base:linear: nished! $ mpirun -np 2 -v hello! 27245 hello running on n0 (o)! 7791 hello running on n1! Hello World, I am process 0! Hello World, I am process 1! killing processes, done ! closing les, done ! sweeping traces, done ! cleaning up registered objects, done sweeping messages, done! Enter passphrase for /home/nadya/.ssh/id_rsa: ! Identity added: /home/nadya/.ssh/id_rsa (/home/nadya/.ssh/id_rsa)! /opt/lam/gnu/bin/mpicc!
$ lamclean -v!
$ lamhalt!
2006 UC Regents!
22!
2.
3. 4.
5. 6. or
Example 2 details!
If using frontend and compute nodes in machines le use! !mpirun -np 2 -machinele machines cpi ! !# If using only compute nodes in machine le use ! !mpirun -nolocal -np 2 -machinele machines cpi !
!#
"# "# "# "#
-nolocal - don$t start job on frontend! -np 2 - start job on 2 nodes! -machinele machines - nodes are specied in machinesle! cpi - start program cpi!
2006 UC Regents!
24!
More examples!
!# See
"#
!# Additional
"#
examples in!
2006 UC Regents!
25!
MPICH in Rocks uses shared memory segments to pass messages between processes on the same node! When an MPICH program crashes, it doesn$t properly cleanup these shared memory segments! After a program crash, run:! $ cluster-fork sh /opt/mpich/gnu/sbin/cleanipcs! NOTE: this removes all shared memory segments for your user id! "# If you have other live MPI programs running, this will remove their shared memory segments too and cause that program to fail !
!#
2006 UC Regents!
26!
3.#
2006 UC Regents!
27!
contents!
#!/bin/tcsh! #$ -S /bin/tcsh! setenv MPI=/path/to/MPI/binaries! ! $MPI/mpirun -machinele machines -np $NSLOTS appname!
2006 UC Regents!
28!
Submit le options!
# meet given resource request! !#$ -l h_rt=600! # specify interpreting shell for the job! !#$ -S /bin/sh! # use path for stadard output of job! !#$ -o path! # execute from current dir !#$ -cwd! # run on 32 processes in mpich PE! !#$ -pe mpich 32! # Export all environmental variables! !#$ -V! # Export these environmental variables! !#$ -v MPI_ROOT,FOOBAR=BAR!
2006 UC Regents!
29!
Online resources!
MPI standard: ! !www-unix.mcs.anl.gov/mpi! Local Area Multicomputer MPI (LAM MPI): ! www.osc.edu/lam.html! MPICH: www.mcs.anl.gov/mpi/mpich Aggregate Function MPI (AFMPI):! garage.ecn.purdue.edu/~papers Lam tutorial !www.lam-mpi.org/tutorials/one-step/lam.php
2006 UC Regents!
30!
Glossary!
MPI - message passing interface! PVM - parallel virtual machine! LAM - local area multicomputer! P4 - 3rd generation parallel programming library, includes! message-passing and shared-memory components! Chameleon - high-performance portability package for! ! ! message passing on parallel supercomputers! Zipcode - portable system for writing of scalable libraries! ADI - abstract device architecture!
2006 UC Regents! 31!
Glossary (cont$d)!
SIMD - Single Instruction Multiple Data! SPMD - Single Program Multiple Data ! MIMD - Multiple Instruction Multiple Data! MPMD - Multiple Program Multiple Data!
2006 UC Regents!
32!