Академический Документы
Профессиональный Документы
Культура Документы
Part - II
Message Passing Interface
Dheeraj Bhardwaj
Department of Computer Science & Engineering
Indian Institute of Technology, Delhi – 110016 India
http://www.cse.iitd.ac.in/~dheerajb
Dheeraj Bhardwaj <dheerajb@cse.iitd.ac.in> 1
Message Passing Interface
Outlines
? Basics of MPI
? How to compile and execute MPI programs?
? MPI library calls used in Example program
? MPI point-to-point communication
? MPI advanced point-to-point communication
? MPI Collective Communication and Computations
? MPI Datatypes
Message Passing Interface
Blocking Send
A typical blocking send looks like
send (dest, type, address, length)
Where
Point-to-Point Communications
MPI_Send
SEND has been issued and the message has been received.
MPI_Recv
R
Message Passing Interface
wait
Transfer doesn’t begin until
word has arrived that MPI_RECV task continues when data
corresponding MPI_RECV transfer to user’s buffer is
has been posted complete
Fortran
Message Passing Interface
S
R
transfer doesn’t begin until word MPI_WAIT no interruption if
MPI_IRECV
has arrived that corresponding wait is late
MPI_IRECV has been posted enough
Dheeraj Bhardwaj <dheerajb@cse.iitd.ac.in> 11
MPI Communication Modes
? Synchronous mode
? Buffered mode
S
R
task waits
MPI_RECV
Receive MPI_RECV
Message type
? MPI datatypes:
• Basic types
? C:
int MPI_Type_contiguous (int count, MPI_Datatype
oldtype,MPI_Datatype *newtype);
? Fortran :
Message Passing Interface
? Fortran
MPI_Type_vector (count, blocklength, stride, oldtype, newtype, ierror)
Extent of a Datatype
? Fortran
? Fortran :
MPI_Type_Struct (count, array_of_blocklengths,
array_of_displacements, array_of_types, newtype, ierror)
Message Passing Interface
Committing a datatype
? Once a datatype has been constructed, it needs to be
committed before it is used.
? C
int MPI_Type_Commit (MPI_Datatype *datatype);
Message Passing Interface
? Fortran
MPI_Type_Commit (datatype, ierror)
integer datatype, ierror
? Potential saving
“ Allocation of MPI_Request
? Variation of example
Message Passing Interface
Collective Communication
? Examples:
• Barrier synchronization.
• Broadcast, scatter, gather.
Message Passing Interface
• Data movement
• Collective computation
Barrier
A barrier insures that all processor reach a specified location
within the code before continuing.
? C:
int MPI_Barrier (MPI_Comm comm);
? Fortran:
Message Passing Interface
? C:
int MPI_Bcast ( void *buffer, int count, MPI_Datatype
datatype, int root, MPI_Comm comm);
? Fortran:
MPI_bcast (buffer, count, datatype, root, comm,
Message Passing Interface
ierror)
<type> buffer(*)
integer count, datatype, root, comm, ierror
? Examples:
Fortran
MPI_Reduce (sendbuf, recvbuf, count, datatype, op,
root, comm, ierror)
<type> sendbuf (*), recvbuf (*)
integer count, datatype, op, root, comm,
integer ierror
C
int MPI_Reduce (void *sendbuf, void *recvbuf, int
count, MPI_Datatype datatype, MPI_Op
Message Passing Interface
P0 A P0 A
P1 Broadcast P1 A
P2 P2 A
P3 P3 A
P0 A B C D P0 A
P1 Scatter P1 B
Message Passing Interface
P2 P2 C
Gather
P3 P3 D
Representation of collective data movement in MPI
P0 A0 P0
P1 A1 Reduce (A,B,P1,SUM) P1 =A0+A1+A2+A3
P2 A2 P2
P3 A3 P3
P0 A0 P0
P1 A1 Reduce (A,B,P2,MAX) P1 = MAXIMUM
P2
Message Passing Interface
P2 A2
P3 A3 P3
P0 A P0 A B C D
P1 B All gather P1 A B C D
P2 C P2 A B C D
P3 D P3 A B C D
P0 A0 A1 A2 A3 P0 A0 B0 C0 D0
P1 B0 B1 B2 B3 All to All P1 A1 B1 C1 D1
Message Passing Interface
P2 C0 C1 C2 C3 P2 A2 B2 C2 D2
P3 D0 D1 D2 D3 P3 A3 B3 C3 D3
Representation of collective data movement in MPI
? General
• Communicators combine context and group for
message security
• Thread safety
? Point-to-Point communication
• Structured buffers and derived datatypes, heterogeneity
• Modes: normal (blocking and non-blocking),
Message Passing Interface
? Positives
Pros
? Best scaling seen in practice
? Simple memory model
? Simple to understand conceptually
? Can send messages using any kind of data
? Not limited to “shared -data”
Message Passing Interface
Cons
? Debugging is not easy
? Development of production codes is much difficult
and time consuming
? Codes may be indeterministic in nature, using
asynchronous communication
? Non-contiguous data handling either use derived data
Message Passing Interface