SlideShare a Scribd company logo
1 of 36
Lecture 3Lecture 3
Point-to-PointPoint-to-Point
CommunicationsCommunications
Dr. Muhammad Hanif Durad
Department of Computer and Information Sciences
Pakistan Institute Engineering and Applied Sciences
hanif@pieas.edu.pk
Some slides have bee adapted with thanks from some other
lectures available on Internet
Dr. Hanif Durad 2
Lecture Outline
 Models for Communication
 Brief introduction to MPI
 Basic concepts
 Learn 6 most commonly used functions
 Introduce “collective” operations
IntroMPI.ppt
MPI Basic Send/Receive
3
 We need to fill in the details in
 things that need specifying:
 How will “data” be described?
 How will processes be identified?
 How will the receiver recognize/screen messages?
 What will it mean for these operations to complete?
Process 0 Process 1
Send(data)
Receive(data)
IntroMPI.ppt
Some Basic Concepts
 Processes can be collected into groups
 Each message is sent in a context, and must be received
in the same context
 Provides necessary support for libraries
 A group and context together form a communicator
 A process is identified by its rank in the group associated
with a communicator
 There is a default communicator whose group contains all
initial processes, called MPI_COMM_WORLD
Dr. Hanif Durad 4
IntroMPI.ppt
MPI Datatypes
 The data in a message to send or receive 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)
 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, in
particular ones for subarrays
 May hurt performance if datatypes are complex
5Dr. Hanif Durad
IntroMPI.ppt
MPI Tags
 Messages are sent with an accompanying user-defined
integer tag, to assist the receiving process in identifying
the message
 Messages can be screened at the receiving end by
specifying a specific tag, or not screened by specifying
MPI_ANY_TAG as the tag in a receive
 Some non-MPI message-passing systems have called
tags “message types”. MPI calls them tags to avoid
confusion with datatypes
Dr. Hanif Durad 6
IntroMPI.ppt
Blocking Point-to-Point
Communication (1/2)
 MPI_Send()
 Basic blocking send operation. Routine returns only after the
application buffer in the sending task is free for reuse.
 MPI_Recv()
 Receive a message and block until the requested data is
available in the application buffer in the receiving task.
 MPI_Ssend()
 synchronous blocking send
7Dr. Hanif Durad
Comm.ppt
Blocking Point-to-Point
Communication (2/2)
 MPI_Bsend()
 buffered blocking send
 MPI_Rsend()
 blocking ready send, use with great care
 MPI_Sendrecv()
 Send a message and post a receive before blocking. Will block
until the sending application buffer is free for reuse and until the
receiving application buffer contains the received message.
8Dr. Hanif Durad
Comm.ppt
MPI Basic (Blocking) Send
 MPI_SEND(start, count, datatype, dest, tag, comm)
 The message buffer is described by (start, count, datatype).
 The target process is specified by dest, which is the rank of the target process in
the communicator specified by comm.
 When this function returns, the data has been delivered to the system and the
buffer can be reused.
 Important: The message may not have been received by the target process.
Dr. Hanif Durad 9
A(10)
B(20)
MPI_Send( A, 10, MPI_DOUBLE, 1, …) MPI_Recv( B, 20, MPI_DOUBLE, 0, … )
IntroMPI.ppt
MPI Basic (Blocking) Receive
MPI_RECV(start, count, datatype, source, tag,comm, status)
 Waits until a matching (both source and tag) message is received from the
system, and the buffer can be used
 source is rank in communicator specified by comm, or MPI_ANY_SOURCE
 tag is a tag to be matched on or MPI_ANY_TAG
 receiving fewer than count occurrences of datatype is OK, but receiving more
is an error
 status contains further information (e.g. size of message)
Dr. Hanif Durad 10
MPI_Send( A, 10, MPI_DOUBLE, 1, …) MPI_Recv( B, 20, MPI_DOUBLE, 0, … )
A(10)
B(20)
IntroMPI.ppt
Blocking Operations pp2003lecture4.ppt
A Simple MPI Program (C)
#include "mpi.h"
#include <stdio.h>
int main( int argc, char *argv[])
{
int rank, buf;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
/* Process 0 sends and Process 1 receives */
if (rank == 0) {
buf = 123456;
MPI_Send( &buf, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}
else if (rank == 1) {
MPI_Recv( &buf, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
&status );
printf( "Received %dn", buf );
}
MPI_Finalize();
return 0;
}
Dr. Hanif Durad 12
IntroMPI.pptProgram name blocking.c
A Simple MPI Program (Fortran)
program main
include 'mpif.h'
integer rank, buf, ierr, status(MPI_STATUS_SIZE)
call MPI_Init(ierr)
call MPI_Comm_rank( MPI_COMM_WORLD, rank, ierr )
! Process 0 sends and Process 1 receives
if (rank .eq. 0) then
buf = 123456
call MPI_Send( buf, 1, MPI_INTEGER, 1, 0, MPI_COMM_WORLD, ierr )
else if (rank .eq. 1) then
call MPI_Recv( buf, 1, MPI_INTEGER, 0, 0, MPI_COMM_WORLD, status, ierr )
print *, "Received ", buf
endif
call MPI_Finalize(ierr)
end
Dr. Hanif Durad 13
IntroMPI.pptProgram name blocking.f90
A Simple MPI Program (C++)
#include "mpi.h"
#include <iostream>
int main( int argc, char *argv[])
{
int rank, buf;
MPI::Init(argc, argv);
rank = MPI::COMM_WORLD.Get_rank();
// Process 0 sends and Process 1 receives
if (rank == 0)
{
buf = 123456;
MPI::COMM_WORLD.Send( &buf, 1, MPI::INT, 1, 0 );
}
else if (rank == 1)
{
MPI::COMM_WORLD.Recv( &buf, 1, MPI::INT, 0, 0 );
std::cout << "Received" << buf << "n";
}
MPI::Finalize();
return 0;
} Dr. Hanif Durad 14
IntroMPI.pptProgram name blocking.cpp
Retrieving Further Information
(C)
 Status is a data structure allocated in the user’s
program.
 In C:
 int recvd_tag, recvd_from, recvd_count;
 MPI_Status status;
 MPI_Recv(..., MPI_ANY_SOURCE, MPI_ANY_TAG, ...,
&status )
 recvd_tag = status.MPI_TAG;
 recvd_from = status.MPI_SOURCE;
 MPI_Get_count( &status, datatype, &recvd_count );
Dr. Hanif Durad 15
Retrieving Further Information
(Fortran)
 In Fortran:
 integer recvd_tag, recvd_from, recvd_count
 integer status(MPI_STATUS_SIZE)
 call MPI_RECV(..., MPI_ANY_SOURCE,
MPI_ANY_TAG, .. status, ierr)
 tag_recvd = status(MPI_TAG)
 recvd_from = status(MPI_SOURCE)

call MPI_GET_COUNT(status, datatype, recvd_count, ierr)
Dr. Hanif Durad 16
Retrieving Further Information
(C++)
 Status is a data structure allocated in the user’s
program.
 In C++:
int recvd_tag, recvd_from, recvd_count;
MPI::Status status;
Comm.Recv(..., MPI::ANY_SOURCE, MPI::ANY_TAG,
...,
status )
recvd_tag = status.Get_tag();
recvd_from = status.Get_source();
recvd_count = status.Get_count( datatype );
Dr. Hanif Durad 17
Tags and Contexts
 Separation of messages used to be accomplished by use of
tags, but
 this requires libraries to be aware of tags used by other libraries.
 this can be defeated by use of “wild card” tags.
 Contexts are different from tags
 no wild cards allowed
 allocated dynamically by the system when a library sets up a
communicator for its own use.
 User-defined tags still provided in MPI for user
convenience in organizing application 18
IntroMPI.ppt
Home Work 1
 We have just used MPI_Send() and MPI_Recv()
Try to use other blocking functions listed
Dr. Hanif Durad 19
Flavors of message passing
 Synchronous used for routines that return when
the message transfer has been completed
 Synchronous send waits until the complete message can
be accepted by the receiving process before sending the
message (send suspends until receive)
 Synchronous receive will wait until the message it is
expecting arrives (receive suspends until message sent)
 Also called blocking
A B
request to send
acknowledgement
message
lecture2.ppt
Synchronous send() and recv()
using 3-way protocol (1/2)
Dr. Hanif Durad 21
Process 1 Process 2
send();
recv();
Suspend
Time
process
Acknowledgment
MessageBoth processes
continue
(a) When send() occurs before recv()
Request to send
slides2.ppt
Synchronous send() and recv()
using 3-way protocol (2/2)
Dr. Hanif Durad 22
Process 1 Process 2
recv();
send();
Suspend
Time
process
Acknowledgment
MessageBoth processes
contin ue
(b) When recv() occurs before send()
Request to send
slides2.ppt
Nonblocking message passing
 Nonblocking sends return whether or not the message has
been received
 If receiving processor not ready, message may be stored in
message buffer
 Message buffer used to hold messages being sent by A prior to
being accepted by receive in B
 MPI:

routines that use a message buffer and return after their local
actions complete are blocking (even though message transfer
may not be complete)

Routines that return immediately are non-blocking
A B
message
buffer
4 Communication Modes in MPI
(1/3)
 Standard mode
 Not assumed that corresponding receive routine has
started.
 Amount of buffering not defined by MPI. If buffering
provided, send could complete before receive reached
 Buffered(asynchronous) mode
 Send may start and return before a matching receive.
Necessary to specify buffer space via routine
MPI_Buffer_attach().
Dr. Hanif Durad 24
lecture4.ppt/slides2.ppt
Communication Modes in MPI
(2/3)
 Synchronous mode
 Send and receive can start before each other but can only
complete together
 Ready mode
 Send can only start if matching receive already reached,
otherwise error. Use with care
Dr. Hanif Durad 25
lecture4.ppt/slides2.ppt
Communication Modes in MPI
(3/3)
 Each of the four modes can be applied to both
blocking and nonblocking send routines.
 Only the standard mode is available for the
blocking and nonblocking receive routines.
 Any type of send routine can be used with any
type of receive routine.
Dr. Hanif Durad 26
slides2.ppt
A Real Blocking Program (1/3)
#include "mpi.h"
#include <iostream>
int main(int argc, char *argv[])
{
#define MSGLEN 2048
int ITAG_A = 100,ITAG_B = 200;
int irank, i, idest, isrc, istag, iretag;
float rmsg1[MSGLEN];
float rmsg2[MSGLEN];
MPI::Status recv_status;
MPI::Init(argc, argv);
irank = MPI::COMM_WORLD.Get_rank(); 27
Program name deadlock.cpp
A Real Blocking Program (2/3)
for (i = 1; i <= MSGLEN; i++)
{
rmsg1[i] = 100;
rmsg2[i] = -100;
}
if ( irank == 0 )
{
idest = 1;
isrc = 1;
istag = ITAG_A;
iretag = ITAG_B;
}
else if ( irank == 1 )
{
idest = 0;
isrc = 0;
istag = ITAG_B;
iretag = ITAG_A;
}
28
A Real Blocking Program (3/3)
std::cout << "Task " << irank << " has sent the message"
<<std::endl;
MPI::COMM_WORLD.Ssend(rmsg1, MSGLEN, MPI::FLOAT,
idest, istag);
MPI::COMM_WORLD.Recv(rmsg2, MSGLEN, MPI::FLOAT,
isrc, iretag, recv_status);
std::cout << "Task " << irank << " has received the message"
<<std::endl;
MPI::Finalize();
}
29
Nonblocking Point-to-Point
Communication (1/2)
 MPI_Isend(), MPI_Irecv()
 identifies the send/receive buffer. Computation proceeds
immediately. A communication request handle is returned for
handling the pending message status. The program must use
calls to MPI_Wait or MPI_Test to determine when the
operation completes.
 MPI_Issend(), MPI_Ibsend(), MPI_Irsend()
 non-blocking versions
Dr. Hanif Durad 30
Comm.ppt
Nonblocking Point-to-Point
Communication (2/2)
 MPI_Test(), MPI_Testany, MPI_Testall, MPI_Testsome()
 checks the status of a specified non-blocking send or receive
operation
 MPI_Wait(), MPI_Waitany(), MPI_Waitall(),
MPI_Waitsome()
 blocks until a specified non-blocking send or receive operation
has completed
 MPI_Probe()
 performs a non-blocking test for a message.
Dr. Hanif Durad 31
Comm.ppt
Non-Blocking Operations lecture4.ppt
Fixing Deadlock (1/3)
#include "mpi.h"
#include <iostream>
int main(int argc, char *argv[])
{
#define MSGLEN 2048
int ITAG_A = 100,ITAG_B = 200;
int irank, i, idest, isrc, istag, iretag;
float rmsg1[MSGLEN];
float rmsg2[MSGLEN];
MPI::Status irstatus, isstatus;
MPI::Request request;
MPI::Init(argc, argv);
irank = MPI::COMM_WORLD.Get_rank(); 33
Program name deadlock-fix.cpp DTwww.nccs.gov
Fixing Deadlock (2/3)
for (i = 1; i <= MSGLEN; i++)
{
rmsg1[i] = 100;
rmsg2[i] = -100;
}
if ( irank == 0 )
{
idest = 1;
isrc = 1;
istag = ITAG_A;
iretag = ITAG_B;
}
else if ( irank == 1 )
{
idest = 0;
isrc = 0;
istag = ITAG_B;
iretag = ITAG_A;
}
Dr. Hanif Durad 34
Program name deadlock-fix.cpp
Fixing Deadlock (3/3)
std::cout << "Task " << irank << " has sent the message" <<std::endl;
request = MPI::COMM_WORLD.Isend(rmsg1, MSGLEN,
MPI::FLOAT, idest, istag);
MPI::COMM_WORLD.Recv(rmsg2, MSGLEN, MPI::FLOAT, isrc,
iretag, irstatus);
MPI_Wait(request,isstatus);
std::cout << "Task " << irank << " has received the message" <<
std::endl;
MPI::Finalize();
}
Dr. Hanif Durad 35
Program name deadlock-fix.cpp
Home Work 2
 We have just used MPI_Isend(). Try to use other
non-blocking functions listed
Dr. Hanif Durad 36

More Related Content

What's hot

Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process CommunicationAdeel Rasheed
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Akhila Prabhakaran
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationPradeep Kumar TS
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationMohd Tousif
 
Remote Procedure Call in Distributed System
Remote Procedure Call in Distributed SystemRemote Procedure Call in Distributed System
Remote Procedure Call in Distributed SystemPoojaBele1
 
High Performance Computing using MPI
High Performance Computing using MPIHigh Performance Computing using MPI
High Performance Computing using MPIAnkit Mahato
 
Interprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SInterprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SHussain Ala'a Alkabi
 
The Message Passing Interface (MPI) in Layman's Terms
The Message Passing Interface (MPI) in Layman's TermsThe Message Passing Interface (MPI) in Layman's Terms
The Message Passing Interface (MPI) in Layman's TermsJeff Squyres
 
Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.MITS Gwalior
 
Inter process communication using Linux System Calls
Inter process communication using Linux System CallsInter process communication using Linux System Calls
Inter process communication using Linux System Callsjyoti9vssut
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationRJ Mehul Gadhiya
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linuxMazenetsolution
 
Implementation of FIFO in Linux
Implementation of FIFO in LinuxImplementation of FIFO in Linux
Implementation of FIFO in LinuxTushar B Kute
 

What's hot (20)

MPI Tutorial
MPI TutorialMPI Tutorial
MPI Tutorial
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Remote Procedure Call in Distributed System
Remote Procedure Call in Distributed SystemRemote Procedure Call in Distributed System
Remote Procedure Call in Distributed System
 
Message passing in Distributed Computing Systems
Message passing in Distributed Computing SystemsMessage passing in Distributed Computing Systems
Message passing in Distributed Computing Systems
 
High Performance Computing using MPI
High Performance Computing using MPIHigh Performance Computing using MPI
High Performance Computing using MPI
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Interprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SInterprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.S
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Igrp
IgrpIgrp
Igrp
 
The Message Passing Interface (MPI) in Layman's Terms
The Message Passing Interface (MPI) in Layman's TermsThe Message Passing Interface (MPI) in Layman's Terms
The Message Passing Interface (MPI) in Layman's Terms
 
Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.
 
Open mp
Open mpOpen mp
Open mp
 
IPC
IPCIPC
IPC
 
Inter process communication using Linux System Calls
Inter process communication using Linux System CallsInter process communication using Linux System Calls
Inter process communication using Linux System Calls
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linux
 
Implementation of FIFO in Linux
Implementation of FIFO in LinuxImplementation of FIFO in Linux
Implementation of FIFO in Linux
 

Viewers also liked

E commerce business
E commerce businessE commerce business
E commerce businessUday Kakkar
 
Tina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and RollTina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and Rollrockandrollboxmay21
 
Tina Turner A Rainha do Rock and Roll
Tina Turner A Rainha do Rock and RollTina Turner A Rainha do Rock and Roll
Tina Turner A Rainha do Rock and Rollrockandrollboxmay21
 
Tina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and RollTina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and Rollrockandrollboxmay21
 
Final Paper Dela Pena, Arla Jemimah BACR 2-2
Final Paper Dela Pena, Arla Jemimah BACR 2-2Final Paper Dela Pena, Arla Jemimah BACR 2-2
Final Paper Dela Pena, Arla Jemimah BACR 2-2AJ Dela Pena
 
Yo, mi región , mi cultura , betsy vidal
Yo, mi región , mi cultura , betsy vidalYo, mi región , mi cultura , betsy vidal
Yo, mi región , mi cultura , betsy vidalBetsy01
 
Tina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and RollTina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and Rollrockandrollboxmay21
 
Diseã±o lã­neas de conducciã³n e impulsiã³n
Diseã±o lã­neas de conducciã³n e impulsiã³nDiseã±o lã­neas de conducciã³n e impulsiã³n
Diseã±o lã­neas de conducciã³n e impulsiã³nFidel Dominguez Gaspar
 
Fantastic Fingers®: Addressing young students fine motor needs through a coll...
Fantastic Fingers®: Addressing young students fine motor needs through a coll...Fantastic Fingers®: Addressing young students fine motor needs through a coll...
Fantastic Fingers®: Addressing young students fine motor needs through a coll...Ingrid C. King
 
Tina Turner A Rainha do Rock and Roll
Tina Turner A Rainha do Rock and RollTina Turner A Rainha do Rock and Roll
Tina Turner A Rainha do Rock and Rollrockandrollboxmay21
 

Viewers also liked (20)

Chapter 6 pc
Chapter 6 pcChapter 6 pc
Chapter 6 pc
 
Chapter 1 pc
Chapter 1 pcChapter 1 pc
Chapter 1 pc
 
Chapter 3 pc
Chapter 3 pcChapter 3 pc
Chapter 3 pc
 
Chapter 5 pc
Chapter 5 pcChapter 5 pc
Chapter 5 pc
 
Chapter 4 pc
Chapter 4 pcChapter 4 pc
Chapter 4 pc
 
E commerce business
E commerce businessE commerce business
E commerce business
 
Hellodochery
HellodocheryHellodochery
Hellodochery
 
MMP 3
MMP 3MMP 3
MMP 3
 
Tina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and RollTina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and Roll
 
La Reina del Rock and Roll
 La Reina del Rock and Roll La Reina del Rock and Roll
La Reina del Rock and Roll
 
Tina Turner A Rainha do Rock and Roll
Tina Turner A Rainha do Rock and RollTina Turner A Rainha do Rock and Roll
Tina Turner A Rainha do Rock and Roll
 
Tina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and RollTina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and Roll
 
Final Paper Dela Pena, Arla Jemimah BACR 2-2
Final Paper Dela Pena, Arla Jemimah BACR 2-2Final Paper Dela Pena, Arla Jemimah BACR 2-2
Final Paper Dela Pena, Arla Jemimah BACR 2-2
 
A Rainha do Rock and Roll
A Rainha do Rock and RollA Rainha do Rock and Roll
A Rainha do Rock and Roll
 
Yo, mi región , mi cultura , betsy vidal
Yo, mi región , mi cultura , betsy vidalYo, mi región , mi cultura , betsy vidal
Yo, mi región , mi cultura , betsy vidal
 
Tina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and RollTina Turner The Queen of Rock and Roll
Tina Turner The Queen of Rock and Roll
 
Diseã±o lã­neas de conducciã³n e impulsiã³n
Diseã±o lã­neas de conducciã³n e impulsiã³nDiseã±o lã­neas de conducciã³n e impulsiã³n
Diseã±o lã­neas de conducciã³n e impulsiã³n
 
Fantastic Fingers®: Addressing young students fine motor needs through a coll...
Fantastic Fingers®: Addressing young students fine motor needs through a coll...Fantastic Fingers®: Addressing young students fine motor needs through a coll...
Fantastic Fingers®: Addressing young students fine motor needs through a coll...
 
Tina Turner A Rainha do Rock and Roll
Tina Turner A Rainha do Rock and RollTina Turner A Rainha do Rock and Roll
Tina Turner A Rainha do Rock and Roll
 
Catálogo ttc 2017
Catálogo ttc 2017Catálogo ttc 2017
Catálogo ttc 2017
 

Similar to Point-to-Point Communicationsin MPI

Similar to Point-to-Point Communicationsin MPI (20)

Intro to MPI
Intro to MPIIntro to MPI
Intro to MPI
 
MPI
MPIMPI
MPI
 
Mpi
Mpi Mpi
Mpi
 
Message passing Programing and MPI.
Message passing Programing and MPI.Message passing Programing and MPI.
Message passing Programing and MPI.
 
cs556-2nd-tutorial.pdf
cs556-2nd-tutorial.pdfcs556-2nd-tutorial.pdf
cs556-2nd-tutorial.pdf
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
Ch03
Ch03Ch03
Ch03
 
Chapter 3 - Processes
Chapter 3 - ProcessesChapter 3 - Processes
Chapter 3 - Processes
 
3 processes
3 processes3 processes
3 processes
 
Tutorial on Parallel Computing and Message Passing Model - C3
Tutorial on Parallel Computing and Message Passing Model - C3Tutorial on Parallel Computing and Message Passing Model - C3
Tutorial on Parallel Computing and Message Passing Model - C3
 
MPI
MPIMPI
MPI
 
Open MPI 2
Open MPI 2Open MPI 2
Open MPI 2
 
MPI.pptx
MPI.pptxMPI.pptx
MPI.pptx
 
Parallel and Distributed Computing Chapter 10
Parallel and Distributed Computing Chapter 10Parallel and Distributed Computing Chapter 10
Parallel and Distributed Computing Chapter 10
 
Parallel computing(2)
Parallel computing(2)Parallel computing(2)
Parallel computing(2)
 
More mpi4py
More mpi4pyMore mpi4py
More mpi4py
 
Ch4 OS
Ch4 OSCh4 OS
Ch4 OS
 
OS_Ch4
OS_Ch4OS_Ch4
OS_Ch4
 
Process
ProcessProcess
Process
 
OSCh4
OSCh4OSCh4
OSCh4
 

More from Hanif Durad

More from Hanif Durad (16)

Chapter 26 aoa
Chapter 26 aoaChapter 26 aoa
Chapter 26 aoa
 
Chapter 25 aoa
Chapter 25 aoaChapter 25 aoa
Chapter 25 aoa
 
Chapter 24 aoa
Chapter 24 aoaChapter 24 aoa
Chapter 24 aoa
 
Chapter 23 aoa
Chapter 23 aoaChapter 23 aoa
Chapter 23 aoa
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Chapter 11 ds
Chapter 11 dsChapter 11 ds
Chapter 11 ds
 
Chapter 10 ds
Chapter 10 dsChapter 10 ds
Chapter 10 ds
 
Chapter 9 ds
Chapter 9 dsChapter 9 ds
Chapter 9 ds
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
Chapter 7 ds
Chapter 7 dsChapter 7 ds
Chapter 7 ds
 
Chapter 6 ds
Chapter 6 dsChapter 6 ds
Chapter 6 ds
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Chapter 4 ds
Chapter 4 dsChapter 4 ds
Chapter 4 ds
 
Chapter 3 ds
Chapter 3 dsChapter 3 ds
Chapter 3 ds
 
Chapter 2 ds
Chapter 2 dsChapter 2 ds
Chapter 2 ds
 
Chapter 2 pc
Chapter 2 pcChapter 2 pc
Chapter 2 pc
 

Recently uploaded

AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 

Recently uploaded (20)

AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 

Point-to-Point Communicationsin MPI

  • 1. Lecture 3Lecture 3 Point-to-PointPoint-to-Point CommunicationsCommunications Dr. Muhammad Hanif Durad Department of Computer and Information Sciences Pakistan Institute Engineering and Applied Sciences hanif@pieas.edu.pk Some slides have bee adapted with thanks from some other lectures available on Internet
  • 2. Dr. Hanif Durad 2 Lecture Outline  Models for Communication  Brief introduction to MPI  Basic concepts  Learn 6 most commonly used functions  Introduce “collective” operations IntroMPI.ppt
  • 3. MPI Basic Send/Receive 3  We need to fill in the details in  things that need specifying:  How will “data” be described?  How will processes be identified?  How will the receiver recognize/screen messages?  What will it mean for these operations to complete? Process 0 Process 1 Send(data) Receive(data) IntroMPI.ppt
  • 4. Some Basic Concepts  Processes can be collected into groups  Each message is sent in a context, and must be received in the same context  Provides necessary support for libraries  A group and context together form a communicator  A process is identified by its rank in the group associated with a communicator  There is a default communicator whose group contains all initial processes, called MPI_COMM_WORLD Dr. Hanif Durad 4 IntroMPI.ppt
  • 5. MPI Datatypes  The data in a message to send or receive 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)  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, in particular ones for subarrays  May hurt performance if datatypes are complex 5Dr. Hanif Durad IntroMPI.ppt
  • 6. MPI Tags  Messages are sent with an accompanying user-defined integer tag, to assist the receiving process in identifying the message  Messages can be screened at the receiving end by specifying a specific tag, or not screened by specifying MPI_ANY_TAG as the tag in a receive  Some non-MPI message-passing systems have called tags “message types”. MPI calls them tags to avoid confusion with datatypes Dr. Hanif Durad 6 IntroMPI.ppt
  • 7. Blocking Point-to-Point Communication (1/2)  MPI_Send()  Basic blocking send operation. Routine returns only after the application buffer in the sending task is free for reuse.  MPI_Recv()  Receive a message and block until the requested data is available in the application buffer in the receiving task.  MPI_Ssend()  synchronous blocking send 7Dr. Hanif Durad Comm.ppt
  • 8. Blocking Point-to-Point Communication (2/2)  MPI_Bsend()  buffered blocking send  MPI_Rsend()  blocking ready send, use with great care  MPI_Sendrecv()  Send a message and post a receive before blocking. Will block until the sending application buffer is free for reuse and until the receiving application buffer contains the received message. 8Dr. Hanif Durad Comm.ppt
  • 9. MPI Basic (Blocking) Send  MPI_SEND(start, count, datatype, dest, tag, comm)  The message buffer is described by (start, count, datatype).  The target process is specified by dest, which is the rank of the target process in the communicator specified by comm.  When this function returns, the data has been delivered to the system and the buffer can be reused.  Important: The message may not have been received by the target process. Dr. Hanif Durad 9 A(10) B(20) MPI_Send( A, 10, MPI_DOUBLE, 1, …) MPI_Recv( B, 20, MPI_DOUBLE, 0, … ) IntroMPI.ppt
  • 10. MPI Basic (Blocking) Receive MPI_RECV(start, count, datatype, source, tag,comm, status)  Waits until a matching (both source and tag) message is received from the system, and the buffer can be used  source is rank in communicator specified by comm, or MPI_ANY_SOURCE  tag is a tag to be matched on or MPI_ANY_TAG  receiving fewer than count occurrences of datatype is OK, but receiving more is an error  status contains further information (e.g. size of message) Dr. Hanif Durad 10 MPI_Send( A, 10, MPI_DOUBLE, 1, …) MPI_Recv( B, 20, MPI_DOUBLE, 0, … ) A(10) B(20) IntroMPI.ppt
  • 12. A Simple MPI Program (C) #include "mpi.h" #include <stdio.h> int main( int argc, char *argv[]) { int rank, buf; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); /* Process 0 sends and Process 1 receives */ if (rank == 0) { buf = 123456; MPI_Send( &buf, 1, MPI_INT, 1, 0, MPI_COMM_WORLD); } else if (rank == 1) { MPI_Recv( &buf, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status ); printf( "Received %dn", buf ); } MPI_Finalize(); return 0; } Dr. Hanif Durad 12 IntroMPI.pptProgram name blocking.c
  • 13. A Simple MPI Program (Fortran) program main include 'mpif.h' integer rank, buf, ierr, status(MPI_STATUS_SIZE) call MPI_Init(ierr) call MPI_Comm_rank( MPI_COMM_WORLD, rank, ierr ) ! Process 0 sends and Process 1 receives if (rank .eq. 0) then buf = 123456 call MPI_Send( buf, 1, MPI_INTEGER, 1, 0, MPI_COMM_WORLD, ierr ) else if (rank .eq. 1) then call MPI_Recv( buf, 1, MPI_INTEGER, 0, 0, MPI_COMM_WORLD, status, ierr ) print *, "Received ", buf endif call MPI_Finalize(ierr) end Dr. Hanif Durad 13 IntroMPI.pptProgram name blocking.f90
  • 14. A Simple MPI Program (C++) #include "mpi.h" #include <iostream> int main( int argc, char *argv[]) { int rank, buf; MPI::Init(argc, argv); rank = MPI::COMM_WORLD.Get_rank(); // Process 0 sends and Process 1 receives if (rank == 0) { buf = 123456; MPI::COMM_WORLD.Send( &buf, 1, MPI::INT, 1, 0 ); } else if (rank == 1) { MPI::COMM_WORLD.Recv( &buf, 1, MPI::INT, 0, 0 ); std::cout << "Received" << buf << "n"; } MPI::Finalize(); return 0; } Dr. Hanif Durad 14 IntroMPI.pptProgram name blocking.cpp
  • 15. Retrieving Further Information (C)  Status is a data structure allocated in the user’s program.  In C:  int recvd_tag, recvd_from, recvd_count;  MPI_Status status;  MPI_Recv(..., MPI_ANY_SOURCE, MPI_ANY_TAG, ..., &status )  recvd_tag = status.MPI_TAG;  recvd_from = status.MPI_SOURCE;  MPI_Get_count( &status, datatype, &recvd_count ); Dr. Hanif Durad 15
  • 16. Retrieving Further Information (Fortran)  In Fortran:  integer recvd_tag, recvd_from, recvd_count  integer status(MPI_STATUS_SIZE)  call MPI_RECV(..., MPI_ANY_SOURCE, MPI_ANY_TAG, .. status, ierr)  tag_recvd = status(MPI_TAG)  recvd_from = status(MPI_SOURCE)  call MPI_GET_COUNT(status, datatype, recvd_count, ierr) Dr. Hanif Durad 16
  • 17. Retrieving Further Information (C++)  Status is a data structure allocated in the user’s program.  In C++: int recvd_tag, recvd_from, recvd_count; MPI::Status status; Comm.Recv(..., MPI::ANY_SOURCE, MPI::ANY_TAG, ..., status ) recvd_tag = status.Get_tag(); recvd_from = status.Get_source(); recvd_count = status.Get_count( datatype ); Dr. Hanif Durad 17
  • 18. Tags and Contexts  Separation of messages used to be accomplished by use of tags, but  this requires libraries to be aware of tags used by other libraries.  this can be defeated by use of “wild card” tags.  Contexts are different from tags  no wild cards allowed  allocated dynamically by the system when a library sets up a communicator for its own use.  User-defined tags still provided in MPI for user convenience in organizing application 18 IntroMPI.ppt
  • 19. Home Work 1  We have just used MPI_Send() and MPI_Recv() Try to use other blocking functions listed Dr. Hanif Durad 19
  • 20. Flavors of message passing  Synchronous used for routines that return when the message transfer has been completed  Synchronous send waits until the complete message can be accepted by the receiving process before sending the message (send suspends until receive)  Synchronous receive will wait until the message it is expecting arrives (receive suspends until message sent)  Also called blocking A B request to send acknowledgement message lecture2.ppt
  • 21. Synchronous send() and recv() using 3-way protocol (1/2) Dr. Hanif Durad 21 Process 1 Process 2 send(); recv(); Suspend Time process Acknowledgment MessageBoth processes continue (a) When send() occurs before recv() Request to send slides2.ppt
  • 22. Synchronous send() and recv() using 3-way protocol (2/2) Dr. Hanif Durad 22 Process 1 Process 2 recv(); send(); Suspend Time process Acknowledgment MessageBoth processes contin ue (b) When recv() occurs before send() Request to send slides2.ppt
  • 23. Nonblocking message passing  Nonblocking sends return whether or not the message has been received  If receiving processor not ready, message may be stored in message buffer  Message buffer used to hold messages being sent by A prior to being accepted by receive in B  MPI:  routines that use a message buffer and return after their local actions complete are blocking (even though message transfer may not be complete)  Routines that return immediately are non-blocking A B message buffer
  • 24. 4 Communication Modes in MPI (1/3)  Standard mode  Not assumed that corresponding receive routine has started.  Amount of buffering not defined by MPI. If buffering provided, send could complete before receive reached  Buffered(asynchronous) mode  Send may start and return before a matching receive. Necessary to specify buffer space via routine MPI_Buffer_attach(). Dr. Hanif Durad 24 lecture4.ppt/slides2.ppt
  • 25. Communication Modes in MPI (2/3)  Synchronous mode  Send and receive can start before each other but can only complete together  Ready mode  Send can only start if matching receive already reached, otherwise error. Use with care Dr. Hanif Durad 25 lecture4.ppt/slides2.ppt
  • 26. Communication Modes in MPI (3/3)  Each of the four modes can be applied to both blocking and nonblocking send routines.  Only the standard mode is available for the blocking and nonblocking receive routines.  Any type of send routine can be used with any type of receive routine. Dr. Hanif Durad 26 slides2.ppt
  • 27. A Real Blocking Program (1/3) #include "mpi.h" #include <iostream> int main(int argc, char *argv[]) { #define MSGLEN 2048 int ITAG_A = 100,ITAG_B = 200; int irank, i, idest, isrc, istag, iretag; float rmsg1[MSGLEN]; float rmsg2[MSGLEN]; MPI::Status recv_status; MPI::Init(argc, argv); irank = MPI::COMM_WORLD.Get_rank(); 27 Program name deadlock.cpp
  • 28. A Real Blocking Program (2/3) for (i = 1; i <= MSGLEN; i++) { rmsg1[i] = 100; rmsg2[i] = -100; } if ( irank == 0 ) { idest = 1; isrc = 1; istag = ITAG_A; iretag = ITAG_B; } else if ( irank == 1 ) { idest = 0; isrc = 0; istag = ITAG_B; iretag = ITAG_A; } 28
  • 29. A Real Blocking Program (3/3) std::cout << "Task " << irank << " has sent the message" <<std::endl; MPI::COMM_WORLD.Ssend(rmsg1, MSGLEN, MPI::FLOAT, idest, istag); MPI::COMM_WORLD.Recv(rmsg2, MSGLEN, MPI::FLOAT, isrc, iretag, recv_status); std::cout << "Task " << irank << " has received the message" <<std::endl; MPI::Finalize(); } 29
  • 30. Nonblocking Point-to-Point Communication (1/2)  MPI_Isend(), MPI_Irecv()  identifies the send/receive buffer. Computation proceeds immediately. A communication request handle is returned for handling the pending message status. The program must use calls to MPI_Wait or MPI_Test to determine when the operation completes.  MPI_Issend(), MPI_Ibsend(), MPI_Irsend()  non-blocking versions Dr. Hanif Durad 30 Comm.ppt
  • 31. Nonblocking Point-to-Point Communication (2/2)  MPI_Test(), MPI_Testany, MPI_Testall, MPI_Testsome()  checks the status of a specified non-blocking send or receive operation  MPI_Wait(), MPI_Waitany(), MPI_Waitall(), MPI_Waitsome()  blocks until a specified non-blocking send or receive operation has completed  MPI_Probe()  performs a non-blocking test for a message. Dr. Hanif Durad 31 Comm.ppt
  • 33. Fixing Deadlock (1/3) #include "mpi.h" #include <iostream> int main(int argc, char *argv[]) { #define MSGLEN 2048 int ITAG_A = 100,ITAG_B = 200; int irank, i, idest, isrc, istag, iretag; float rmsg1[MSGLEN]; float rmsg2[MSGLEN]; MPI::Status irstatus, isstatus; MPI::Request request; MPI::Init(argc, argv); irank = MPI::COMM_WORLD.Get_rank(); 33 Program name deadlock-fix.cpp DTwww.nccs.gov
  • 34. Fixing Deadlock (2/3) for (i = 1; i <= MSGLEN; i++) { rmsg1[i] = 100; rmsg2[i] = -100; } if ( irank == 0 ) { idest = 1; isrc = 1; istag = ITAG_A; iretag = ITAG_B; } else if ( irank == 1 ) { idest = 0; isrc = 0; istag = ITAG_B; iretag = ITAG_A; } Dr. Hanif Durad 34 Program name deadlock-fix.cpp
  • 35. Fixing Deadlock (3/3) std::cout << "Task " << irank << " has sent the message" <<std::endl; request = MPI::COMM_WORLD.Isend(rmsg1, MSGLEN, MPI::FLOAT, idest, istag); MPI::COMM_WORLD.Recv(rmsg2, MSGLEN, MPI::FLOAT, isrc, iretag, irstatus); MPI_Wait(request,isstatus); std::cout << "Task " << irank << " has received the message" << std::endl; MPI::Finalize(); } Dr. Hanif Durad 35 Program name deadlock-fix.cpp
  • 36. Home Work 2  We have just used MPI_Isend(). Try to use other non-blocking functions listed Dr. Hanif Durad 36