4 P2P-1
4 P2P-1
Communication
Lecture 4
Jan 17, 2023
MPI Program Execution
Memory
Intranode Internode
2
MPI Program Execution
Memory
SENDER
RECEIVER
5
Simple Send/Recv Code (sendmessage.c)
No runtime or
compile-time
error
6
Runtime error
7
Message Size
Sender Receiver
message (13 bytes) Message (10 bytes)
10
Output
0 7 0
Received: Welcome
1 0 7
Multiple Sends and Receives
if (myrank == 0)
MPI_Send (buf, count, MPI_INT, 1, 1, MPI_COMM_WORLD);
else
if (myrank == 1)
MPI_Recv (buf, count, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
0 10
1 10
Multiple Sends and Receives
if (myrank == 0)
MPI_Send (buf, count, MPI_INT, 1, 1, MPI_COMM_WORLD),
MPI_Send (buf, count, MPI_INT, 1, 2, MPI_COMM_WORLD);
else
if (myrank == 1)
MPI_Recv (buf, count, MPI_INT, 0, 1, MPI_COMM_WORLD, &status),
MPI_Recv (buf, count, MPI_INT, 0, 2, MPI_COMM_WORLD, &status);
RECEIVER
Buffering
18
Multiple Sends and Receives
if (myrank == 0)
MPI_Send (buf, count, MPI_INT, 1, 1, MPI_COMM_WORLD),
MPI_Send (buf, count, MPI_INT, 1, 2, MPI_COMM_WORLD);
else
if (myrank == 1)
MPI_Recv (buf, count, MPI_INT, 0, 2, MPI_COMM_WORLD, &status),
MPI_Recv (buf, count, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
21
MPI_Get_count (status.c)
status.MPI_SOURCE
status.MPI_TAG
Output
• Rank 1 of 2 received 1000 elements 22
Timing Send/Recv (timingSend.c)
23
Timing Output
What is the
total time?
One-to-many Sends
25
Many-to-one Sends
a send
operation must
specify a unique
receiver
• MPI_ANY_SOURCE
• Receiver may specify wildcard value for source
• MPI_ANY_TAG
• Receiver may specify wildcard value for tag
28
Receive Out-of-order
No specific
Rectify the order
receive buffer
location 29
Sum of Squares of N numbers
Serial Parallel
for i = 1 to N for i = 1 to N/P
sum += a[i] * a[i] sum += a[i] * a[i]
collate result
30
Sum of Squares
Core
Process
Memory
32