Unformatted text preview:

MA471Fall 2003More Point To Point Communications in MPIMPI_IsendMPI_Isend detailsMPI_Isend analogyMPI_IrecvMPI_Irecv detailsMPI_Irecv analogyMPI_WaitMPI_Wait detailsMPI_TestExample: Isend, Irecv, Wait SequenceExample: Game of SnapPossible (non-optimal)Parallel SetupSymbolic Pseudo-CodeProfiling Your Code Using UpshotInstructions For Using UpshotClean and RecompileResults Viewed In UpshotThe Main Upshot ViewerTime HistoryTime HistoryZoom in on ProfileZoom in on ProfileWith Work Between (Isend,Irecv) and WaitLab ActivityNext LectureMA471Fall 2003Lecture5More Point To Point Communications in MPI• Note: so far we have covered – MPI_Init, MPI_Finalize– MPI_Comm_size, MPI_Comm_rank– MPI_Send, MPI_Recv– MPI_Barrier• Only MPI_Send and MPI_Recv truly communicate messages..• These are “point to point” communicationsi.e. process to process communicationMPI_Isend• Unlike MPI_Send, MPI_Isend does not wait for the output buffer to be free for further use before returning• This mode of action is known as “non-blocking”• http://www-unix.mcs.anl.gov/mpi/www/www3/MPI_Isend.htmlMPI_Isend detailsMPI_Isend: Begins a nonblocking send Synopsisint MPI_Isend( void *buf, int count, MPI_Datatype datatype, intdest, int tag, MPI_Comm comm, MPI_Request *request ) Input Parametersbuf initial address of send buffer (choice) count number of elements in send buffer (integer) datatype datatype of each send buffer element (handle) dest rank of destination (integer) tag message tag (integer) comm communicator (handle) Output Parameterrequest communication request (handle) http://www-unix.mcs.anl.gov/mpi/www/www3/MPI_Isend.htmlMPI_Isend analogy• Analogy time….• Isend is like calling the mailperson to take a letter away and receiving a tracking number• You don’t know if the letter is gone until you check your mailbox (i.e. check online with the tracking number).• When you know the letter is gone you can use the letterbox again… (strained analogy).MPI_Irecv• Post a non-blocking receive request• This routine exits without necessarily completing the message receive• We use MPI_Wait to see if the requested message is in..MPI_Irecv detailsMPI_Irecv: Begins a nonblocking receive Synopsisint MPI_Irecv( void *buf, int count, MPI_Datatype datatype, int source,int tag, MPI_Comm comm, MPI_Request *request ) Input Parametersbuf initial address of receive buffer (choice) count number of elements in receive buffer (integer) datatype datatype of each receive buffer element (handle) source rank of source (integer) tag message tag (integer) comm communicator (handle) Output ParameterRequest communication request (handle) http://www-unix.mcs.anl.gov/mpi/www/www3/MPI_Irecv.htmlMPI_Irecv analogy• Analogy time….• Irecv is like telling the mailbox to anticipate the delivery of a letter.• You don’t know if the letter has arrived until you check your mailbox (i.e. check online with the tracking number).• When you know the letter is here you can open it and read it..MPI_Wait• Wait for a requested MPI operation to completeMPI_Wait details• MPI_Wait: Waits for an MPI send or receive to complete• Synopsis• int MPI_Wait ( MPI_Request *request, MPI_Status *status) • Input Parameter• request request (handle) • Output Parameter• Status status object (Status) . May be MPI_STATUS_NULL. http://www-unix.mcs.anl.gov/mpi/www/www3/MPI_Wait.htmlMPI_Test• MPI_Test: Determines if an MPI send or receive is completewithout blocking.• Synopsis• int MPI_Test( MPI_Request *request, int *flag, MPI_Status *status) • Input Parameter• request request (handle) • Output Parameters• Boolean: flag, flag[0] is true if the request[0] operation hasbeen completed.• Status status object (Status) . May be MPI_STATUS_NULL. http://www-unix.mcs.anl.gov/mpi/www/www3/MPI_Test.htmlExample:Isend, Irecv, Wait SequenceMPI_Request ISENDrequest;MPI_Status ISENDstatus;MPI_Request IRECVrequest;MPI_Status IRECVstatus;char *bufout = strdup("Hello");int bufoutlength = strlen(bufout);int bufinlength = bufoutlength; /* for convenience */char *bufin = (char*) calloc(bufinlength, sizeof(char));int TOprocess = (Nprocs-1) - procID;int TOtag = 10000*procID + TOprocess;int FROMprocess = (Nprocs-1) - procID;int FROMtag = 10000*FROMprocess + procID;fprintf(stdout, "Sending: %s To process %d \n",bufout, TOprocess);info = MPI_Isend(bufout, bufoutlength, MPI_CHAR, TOprocess,TOtag, MPI_COMM_WORLD, &ISENDrequest);info = MPI_Irecv(bufin, bufinlength, MPI_CHAR, FROMprocess,FROMtag, MPI_COMM_WORLD, &IRECVrequest);fprintf(stdout, "Process %d just about to wait for requests to finish\n",procID); MPI_Wait(&IRECVrequest, &IRECVstatus);MPI_Wait(&ISENDrequest, &ISENDstatus);fprintf(stdout, "Received: %s\n From process: %d\n", bufin, FROMprocess); The isend status wait is a courtesyto make sure that the messagehas gone out before we go to finalizeExample: Game of SnapRules:1) Each player receives 26 cards2) Each player plays a card onto their own stack3) If two cards with the same value (i.e 2 of hearts and 2 of clubs) then the firstplayer to shout snap wins both piles of cards…4) Return to 2 unless one player has all the cards.Possible (non-optimal)Parallel Setup• One processor plays role of dealer• Two extra processors each play role of player.Symbolic Pseudo-CodeSay snapto dealerDealDealer:Player 1:Player 2:ShowcardShowcard• Here’s the difficulty – if Dealer is in a blocked call waiting (MPI_Wait) toreceive (MPI_Irecv) from a predetermined player, then the test of snapisunfair.• Solution – dealer should call MPI_Test repeatedly to find out who’s messagearrives first (works since MPI_Test is non-blocking).If(procID == dealer)A) MPI_Isend the cards to each playerB) post MPI_Wait to make sure cards arriveC) post MPI_Test for winning flagElse A) MPI_Irecv the cards from dealerB) MPI_Wait to make sure cards arrivedEndIf(procID != 0)a) MPI_Isend top cardb) MPI_Irecv bottom cardc) MPI_Wait on Isend requestd) MPI_Wait on Irecv requeste) add received card to accumulating pilef) check to see if sent card matches received cardi) if matchMPI_Isend snap message to dealerMPI_Wait for winner message from dealerif winner: collect all cards from accumulating pileif card total =52 or 0… send winning flag to dealerendifreturn to a)Elsea) MPI_Irecv for snap messages from two player processesb) MPI_Test on messages from two players (in random order)c) When MPI_Test


View Full Document

Rice CAAM 471 - Lecture Notes

Download Lecture Notes
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 Lecture Notes 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 Lecture Notes 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?