Message Passing Interface MPI MPI the Message Passing Interface is a library and a software standard developed by the MPI Forum to make use of the most attractive features of existing message passing systems for parallel programming The public release of version 1 0 of MPI was made in June 1994 followed by version 1 1 in June 1995 and and shortly after with version 1 2 which mainly included corrections and specification clarifications An MPI 1 process consists of a C or Fortran 77 program which communicates with other MPI processes by calling MPI routines The MPI routines provide the programmer with a consistent interface across a wide variety of different platforms Version 2 0 a major update of MPI was released July 1997 adding among other features support for dynamic process creation one sided communication and bindings for Fortran 90 and C MPI 2 0 features are not covered here Several commercial and free implementations of MPI 1 2 exist Most widely used free implementations of MPI 1 2 LAM MPI Developed at University of Notre Dame http www lam mpi org MPI CH Developed at Argonne National Laboratory http www unix mcs anl gov mpi mpich MPI CH 1 2 3 is the MPI implementation installed on the CE cluster EECC756 Shaaban 1 lec 7 Spring2002 4 11 2002 Major Features of MPI 1 2 Standard includes 125 functions to provide Point to point message passing Collective communication Support for process groups Support for communication contexts Support for application topologies Environmental inquiry routines Profiling interface EECC756 Shaaban 2 lec 7 Spring2002 4 11 2002 Compiling and Running MPI Programs To compile MPI C programs use mpicc linking flags program name c o program name Ex mpicc hello c o hello To run an MPI compiled program use mpirun np number of processes mpirun options machinefile machinefile program name and arguments The machinefile contains a list of the machines on which you want your MPI programs to run EX mpirun np 4 machinefile rhosts hello starts four processes on the top four machines from machinefile rhosts all running the program hello EECC756 Shaaban 3 lec 7 Spring2002 4 11 2002 MPI Static Process Creation Process Rank MPI 1 2 does not support dynamic process creation i e one cannot spawn a process from within a process as can be done with pvm All processes must be started together at the beginning of the computation Ex mpirun np 4 machinefile rhosts hello There is no equivalent to the pvm pvm spawn call This restriction leads to the direct support of MPI for single programmultiple data SPMD model of computation where each process has the same executable code MPI process Rank A number between 0 to N 1 identifying the process where N is the total number of MPI processes involved in the computation The MPI function MPI Comm rank reports the rank of the calling process The MPI function MPI Comm size reports the total number of MPI processes EECC756 Shaaban 4 lec 7 Spring2002 4 11 2002 MPI Process Initialization Clean Up The first MPI routine called in any MPI program must be the initialization routine MPI INIT Every MPI program must call this routine once before any other MPI routines An MPI program should call the MPI routine MPI FINALIZE when all communications have completed This routine cleans up all MPI data structures etc MPI FINALIZE does NOT cancel outstanding communications so it is the responsibility of the programmer to make sure all communications have completed Once this routine is called no other calls can be made to MPI routines not even MPI INIT so a process cannot later re enroll in MPI EECC756 Shaaban 5 lec 7 Spring2002 4 11 2002 MPI Communicators Handles MPI INIT defines a default communicator called MPI COMM WORLD for each process that calls it All MPI communication calls require a communicator argument and MPI processes can only communicate if they share a communicator Every communicator contains a group which is a list of processes The processes are ordered and numbered consecutively from zero the number of each process being its rank The rank identifies each process within the communicator The group of MPI COMM WORLD is the set of all MPI processes MPI maintains internal data structures related to communications etc and these are referenced by the user through handles Handles are returned to the user from some MPI calls and can be used in other MPI calls EECC756 Shaaban 6 lec 7 Spring2002 4 11 2002 MPI Datatypes The data in a message to sent or received is described by a triple address count datatype where An MPI datatype is recursively defined as Predefined corresponding to a data type from the language e g MPI INT MPI DOUBLE PRECISION A contiguous array of MPI datatypes A strided block of datatypes an indexed array of blocks of datatypes An arbitrary structure of datatypes There are MPI functions to construct custom datatypes such an array of int float pairs or a row of a matrix stored columnwise EECC756 Shaaban 7 lec 7 Spring2002 4 11 2002 MPI Indispensable Functions MPI Init Initialize MPI MPI Finalize Terminate MPI MPI Comm size Find out how many processes there are MPI Comm rank Find out which process I am MPI Send Send a message MPI Recv Receive a message MPI Bcast Broadcasts data MPI Reduce Combines values into a single value EECC756 Shaaban 8 lec 7 Spring2002 4 11 2002 MPI Init MPI Finalize MPI Init The call to MPI Init is required in every MPI program and must be the first MPI call It establishes the MPI execution environment int MPI Init int argc char argv Input argc Pointer to the number of arguments argv Pointer to the argument vector MPI Finalize This routine terminates the MPI execution environment all processes must call this routine before exiting int MPI Finalize void EECC756 Shaaban 9 lec 7 Spring2002 4 11 2002 MPI Comm size This routine determines the size i e number of processes of the group associated with the communicator given as an argument int MPI Comm size MPI Comm comm int size Input comm communicator handle Ouput size number of processes in the group of comm EX MPI Comm size MPI COMM WORLD numprocs EECC756 Shaaban 10 lec 7 Spring2002 4 11 2002 MPI Comm rank The routine determines the rank i e which process number am I of the calling process in the communicator int MPI Comm rank MPI Comm comm int rank Input comm communicator handle Output rank rank of the calling process in the group of comm integer EX MPI Comm rank MPI COMM WORLD myrank EECC756 Shaaban 11 lec 7 Spring2002 4 11 2002 Simple MPI C Program Hello c
View Full Document
Unlocking...