Unformatted text preview:

Hello, world in MPIMPI in nine routines (all you really need)Ten more MPI routines (sometimes useful)Example: Send an integer x from proc 0 to proc 1Some MPI ConceptsSlide 6Slide 7Parameters of blocking sendParameters of blocking receiveSlide 10Hello, world in MPIHello, world in MPI#include <stdio.h>#include "mpi.h"int main( int argc, char *argv[]){ int rank, size; MPI_Init( &argc, &argv ); MPI_Comm_size( MPI_COMM_WORLD, &size ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); printf( "Hello world from process %d of %d\n", rank, size ); MPI_Finalize(); return 0;}MPI in nine routines (all you MPI in nine routines (all you reallyreally need) need)MPI_Init InitializeMPI_Finalize FinalizeMPI_Comm_size How many processes? MPI_Comm_rank Which process am I?MPI_Wtime TimerMPI_Send Send data to one procMPI_Recv Receive data from one procMPI_Bcast Broadcast data to all procsMPI_Reduce Combine data from all procsTen more MPI routines (sometimes useful)Ten more MPI routines (sometimes useful)More group routines (like Bcast and Reduce):MPI_Alltoall, MPI_AlltoallvMPI_Scatter, MPI_GatherNon-blocking send and receive:MPI_Isend, MPI_IrecvMPI_Wait, MPI_Test, MPI_Probe, MPI_IprobeSynchronization:MPI_BarrierExample: Example: Send an integer x from proc 0 to proc 1Send an integer x from proc 0 to proc 1MPI_Comm_rank(MPI_COMM_WORLD,&myrank); /* get rank */ int msgtag = 1;if (myrank == 0) {int x = 17;MPI_Send(&x, 1, MPI_INT, 1, msgtag, MPI_COMM_WORLD);} else if (myrank == 1) {int x;MPI_Recv(&x, 1, MPI_INT,0,msgtag,MPI_COMM_WORLD,&status);}Some MPI ConceptsSome MPI Concepts•Communicator•A set of processes that are allowed to communicate among themselves.•Kind of like a “radio channel”.•Default communicator: MPI_COMM_WORLD•A library can use its own communicator, separated from that of a user program.Some MPI ConceptsSome MPI Concepts•Data Type•What kind of data is being sent/recvd?•Mostly just names for C data types•MPI_INT, MPI_CHAR, MPI_DOUBLE, etc.Some MPI ConceptsSome MPI Concepts•Message Tag•Arbitrary (integer) label for a message•Tag of Send must match tag of Recv•Useful for error checking & debuggingParameters of blocking sendParameters of blocking sendMPI_Send(buf, count, datatype, dest, tag, comm)Address ofNumber of itemsDatatype ofRank of destinationMessage tagCommunicatorsend bufferto sendeach itemprocessParameters of blocking receiveParameters of blocking receiveMPI_Recv(buf, count, datatype, src, tag, comm, status)Address ofMaximum numberDatatype ofRank of sourceMessage tagCommunicatorreceive bufferof items to receiveeach itemprocessStatusafter operationExample: Example: Send an integer x from proc 0 to proc 1Send an integer x from proc 0 to proc 1MPI_Comm_rank(MPI_COMM_WORLD,&myrank); /* get rank */ int msgtag = 1;if (myrank == 0) {int x;MPI_Send(&x, 1, MPI_INT, 1, msgtag, MPI_COMM_WORLD);} else if (myrank == 1) {int x;MPI_Recv(&x, 1,


View Full Document

UCSB CS 240A - MPI

Download MPI
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view MPI and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view MPI 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?