04 cmsc416 Mpi
04 cmsc416 Mpi
• Assignment 0.2 is also posted but not due until Sep 24 11:59 pm
• If you have questions about this assignment, hold off working on it until the topic is covered in class
• https://rookiehpc.org
Process 0
Process 1
Time
Process 0
Process 1
Process 2
Process 3
Time
• Each process runs the same executable, but potentially different parts of the program,
and on different data
• MPI forum was formed in 1992 to standardize message passing models and MPI 1.0
was released in 1994
• v2.0 — 1997
• v3.0 — 2012
• v4.0 — 2021
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &numpes);
printf("Hello world! I'm %d of %d\n", myrank, numpes);
MPI_Finalize();
return 0;
}
Abhinav Bhatele, Alan Sussman (CMSC416 / CMSC616) 8
Compiling and running an MPI program
• Compiling:
• Running:
mpirun -n 2 ./hello
comm: communicator
comm: communicator
comm: communicator
• If the datatypes and count don’t match, this could lead to memory errors and correctness issues
• If a sender sends two messages to a destination, and both match the same receive,
the second message cannot be received if the rst is still pending
• “No-overtaking” messages
• A receive matches a send if certain arguments to the calls match Between a pair
of processes
• What is matched: source, tag, communicator
• If the datatypes and count don’t match, this could lead to memory errors and correctness issues
• If a sender sends two messages to a destination, and both match the same receive,
the second message cannot be received if the rst is still pending
• “No-overtaking” messages
int data;
if (myrank == 0) {
data = 7;
MPI_Send(&data, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
} else if (myrank == 1) {
MPI_Recv(&data, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Process 1 received data %d from process 0\n", data);
}
...
}
Process 0 MPI_Send
MPI_Recv
Process 1
Time
Process 0 MPI_Send
MPI_Recv
Process 1
Time
Process 0 MPI_Send
Deadlock!
MPI_Recv
Process 1
Time
Process 0 MPI_Send
Deadlock!
MPI_Recv
Process 1
Time
...
printf("Process %d received data %d\n”, myrank, data);
}
...
}
...
printf("Process %d received data %d\n”, myrank, data);
}
...
}
...
printf("Process %d received data %d\n”, myrank, data);
}
...
}
...
printf("Process %d received data %d\n”, myrank, data);
}
...
}
...
printf("Process %d received data %d\n”, myrank, data);
}
...
}
• MPI_Cart_create
• MPI_Group_incl