CS 584 Lecture 8 Assignment Message Passing Very

  • Slides: 25
Download presentation
CS 584 Lecture 8 • Assignment?

CS 584 Lecture 8 • Assignment?

Message Passing • Very close to Task-Channel model • Based on multi-processor – Set

Message Passing • Very close to Task-Channel model • Based on multi-processor – Set of independent processors – Connected via some communication net • All communication between processes is done via a message sent from one to the other

MPI • Message Passing Interface • Computation is made of: – One or more

MPI • Message Passing Interface • Computation is made of: – One or more processors – Communicate by calling library routines • MIMD programming model • SPMD most common.

MPI • Processes use point-to-point communication operations • Collective communication operations are also available.

MPI • Processes use point-to-point communication operations • Collective communication operations are also available. • Communication can be modularized by the use of communicators. – MPI_COMM_WORLD is the base. – Used to identify subsets of processors

MPI • Complex, but most problems can be solved using the 6 basic functions.

MPI • Complex, but most problems can be solved using the 6 basic functions. – MPI_Init – MPI_Finalize – MPI_Comm_size – MPI_Comm_rank – MPI_Send – MPI_Recv

MPI Basics • Most all calls require a communicator handle as an argument. –

MPI Basics • Most all calls require a communicator handle as an argument. – MPI_COMM_WORLD • MPI_Init and MPI_Finalize – don’t require a communicator handle – used to begin and end and MPI program – MUST be called to begin and end

MPI Basics • MPI_Comm_size – determines the number of processors in the communicator group

MPI Basics • MPI_Comm_size – determines the number of processors in the communicator group • MPI_Comm_rank – determines the integer identifier assigned to the current process – zero based

MPI Basics #include <stdio. h> #include <mpi. h> main(int argc, char *argv[]) { int

MPI Basics #include <stdio. h> #include <mpi. h> main(int argc, char *argv[]) { int iproc, nproc; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &nproc); MPI_Comm_rank(MPI_COMM_WORLD, &iproc); printf("I am processor %d of %dn", iproc, nproc); MPI_Finalize(); }

MPI Communication • MPI_Send – Sends an array of a given type – Requires

MPI Communication • MPI_Send – Sends an array of a given type – Requires a destination node, size, and type • MPI_Recv – Receives an array of a given type – Same requirements as MPI_Send – Extra parameter • MPI_Status variable.

MPI Basics • Made for both FORTRAN and C • Book attempts to show

MPI Basics • Made for both FORTRAN and C • Book attempts to show both • Standards for C – MPI_ prefix to all calls – First letter of function name is capitalized – Returns MPI_SUCCESS or error code – MPI_Status structure – MPI data types for each C type

Using MPI • Based on rsh – requires a. rhosts file • hostname login

Using MPI • Based on rsh – requires a. rhosts file • hostname login • Path to compiler – MPI_HOME /u 2/faculty/snell/mpich – MPI_ARCH hpux – MPI_BIN MPI_HOME/lib/MPI_ARCH/ch_p 4

Using MPI • Write program • Compile using mpicc in: – /u 2/faculty/snell/mpich/lib/hpux/ch_p 4

Using MPI • Write program • Compile using mpicc in: – /u 2/faculty/snell/mpich/lib/hpux/ch_p 4 • Write process file – host nprocs full_path_to_prog – 0 for nprocs on first line • Run program – prog -p 4 pg process_file args

Example • 2 D finite differences code • Incomplete • In book on page

Example • 2 D finite differences code • Incomplete • In book on page 281

MPI • Message Passing programs are nondeterministic because of concurrency – Consider 2 processes

MPI • Message Passing programs are nondeterministic because of concurrency – Consider 2 processes sending messages to third • MPI does guarantee that 2 messages sent from a single process to another will arrive in order. • It is the programmer's responsibility to ensure computation determinism

MPI & Determinism • Task-Channel model – One reader and one writer per channel

MPI & Determinism • Task-Channel model – One reader and one writer per channel – Separate channel for each communication • MPI – A Process may specify the source of the message – A Process may specify the type of message • Non-Determinism – MPI_ANY_SOURCE or MPI_ANY_TAG

Example for (n = 0; n < nproc/2; n++) { MPI_Send(buff, BSIZE, MPI_FLOAT, rnbor,

Example for (n = 0; n < nproc/2; n++) { MPI_Send(buff, BSIZE, MPI_FLOAT, rnbor, 1, MPI_COMM_WORLD); MPI_Recv(buff, BSIZE, MPI_FLOAT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &status); /* Process the data */ }

Global Operations • Coordinated communication involving multiple processes. • Can be implemented by the

Global Operations • Coordinated communication involving multiple processes. • Can be implemented by the programmer using sends and receives • For convenience, MPI provides a suite of collective communication functions.

Collective Communication • Barrier – Synchronize all processes • Broadcast • Gather – Gather

Collective Communication • Barrier – Synchronize all processes • Broadcast • Gather – Gather data from all processes to one process • Scatter • Reduction – Global sums, products, etc.

Collective Communication

Collective Communication

MPI_Reduce(inbuf, outbuf, count, type, op, root, comm)

MPI_Reduce(inbuf, outbuf, count, type, op, root, comm)

MPI_Reduce with MPI_SUM

MPI_Reduce with MPI_SUM

MPI_Allreduce(inbuf, outbuf, count, type, op, root, comm)

MPI_Allreduce(inbuf, outbuf, count, type, op, root, comm)

Example • Finite Differences code – program 8. 5 page 289 • Notice the

Example • Finite Differences code – program 8. 5 page 289 • Notice the stages – 5 – Signified by the global communication calls

Distribute Problem Size Distribute Input data Exchange Boundary values Find Max Error Collect Results

Distribute Problem Size Distribute Input data Exchange Boundary values Find Max Error Collect Results

Other MPI Features • Asynchronous Communication – MPI_ISend – MPI_Wait and MPI_Test – MPI_Probe

Other MPI Features • Asynchronous Communication – MPI_ISend – MPI_Wait and MPI_Test – MPI_Probe and MPI_Get_count • Modularity – Communicator creation routines • Derived Datatypes