Podcast
Questions and Answers
Which programming languages are commonly supported by MPI implementations?
Which programming languages are commonly supported by MPI implementations?
- C/C++
- Fortran
- Julia
- All of the above (correct)
What is the primary role of mpirun
in executing MPI programs?
What is the primary role of mpirun
in executing MPI programs?
- Compiling the MPI program
- Optimizing network interconnects
- Specifying the number of parallel processes to run (correct)
- Debugging MPI code
In MPI, what does a communicator object primarily define?
In MPI, what does a communicator object primarily define?
- The network topology of the HPC system
- The data type being transmitted
- Sets of processes that can communicate with each other (correct)
- The size of the message buffer
What does the MPI_Comm_rank
function return?
What does the MPI_Comm_rank
function return?
What is the significance of the MPI_Datatype
parameter in MPI_Send
and MPI_Recv
functions?
What is the significance of the MPI_Datatype
parameter in MPI_Send
and MPI_Recv
functions?
In the context of MPI_Send
, what does the 'tag' parameter signify?
In the context of MPI_Send
, what does the 'tag' parameter signify?
What is a key difference between blocking and non-blocking communication in MPI?
What is a key difference between blocking and non-blocking communication in MPI?
Why should wildcards like MPI_ANY_SOURCE
and MPI_ANY_TAG
be avoided in MPI programming?
Why should wildcards like MPI_ANY_SOURCE
and MPI_ANY_TAG
be avoided in MPI programming?
What does the MPI_Request
object represent in non-blocking communication?
What does the MPI_Request
object represent in non-blocking communication?
The function MPI_Waitall
is used to:
The function MPI_Waitall
is used to:
What does the MPI function MPI_Probe
do?
What does the MPI function MPI_Probe
do?
What does MPI guarantee about the order of console output messages from different processes?
What does MPI guarantee about the order of console output messages from different processes?
What is the primary difference between the 'eager' and 'rendezvous' protocols in MPI?
What is the primary difference between the 'eager' and 'rendezvous' protocols in MPI?
Which of the following is NOT a valid MPI datatype?
Which of the following is NOT a valid MPI datatype?
Which of the following best describes MPI?
Which of the following best describes MPI?
Which MPI function is used to initialize the MPI execution environment?
Which MPI function is used to initialize the MPI execution environment?
What is the purpose of the MPI_Finalize()
function?
What is the purpose of the MPI_Finalize()
function?
Which compiler wrapper is typically used for compiling C++ code that utilizes MPI?
Which compiler wrapper is typically used for compiling C++ code that utilizes MPI?
What information is typically included in a batch jobfile for running MPI programs on a cluster?
What information is typically included in a batch jobfile for running MPI programs on a cluster?
Which communicator includes all MPI processes in the current application?
Which communicator includes all MPI processes in the current application?
What value does MPI_COMM_SELF
contain?
What value does MPI_COMM_SELF
contain?
Which type of MPI send operation only returns after the receive operation has started?
Which type of MPI send operation only returns after the receive operation has started?
What is the purpose of MPI_Bsend
?
What is the purpose of MPI_Bsend
?
What happens when the function MPI_Isend is called?
What happens when the function MPI_Isend is called?
Consider a program using MPI_Isend
in a loop but not calling MPI_Wait
or MPI_Waitall
. What is a likely outcome?
Consider a program using MPI_Isend
in a loop but not calling MPI_Wait
or MPI_Waitall
. What is a likely outcome?
What is the use of the status object in MPI_Recv
?
What is the use of the status object in MPI_Recv
?
What is the purpose of the MPI function MPI_Get_count
?
What is the purpose of the MPI function MPI_Get_count
?
What is the purpose of MPI_Test?
What is the purpose of MPI_Test?
What action leads to an 'eager' protocol?
What action leads to an 'eager' protocol?
What does the rendezvous protocol require?
What does the rendezvous protocol require?
Which of the following scenarios would most likely benefit from using non-blocking communications (e.g., MPI_Isend
and MPI_Irecv
) over blocking communications?
Which of the following scenarios would most likely benefit from using non-blocking communications (e.g., MPI_Isend
and MPI_Irecv
) over blocking communications?
A program uses non-blocking sends (MPI_Isend
) and receives (MPI_Irecv
), but occasionally hangs. What could be a potential reason?
A program uses non-blocking sends (MPI_Isend
) and receives (MPI_Irecv
), but occasionally hangs. What could be a potential reason?
Which of the following is a key advantage of using MPI in parallel computing?
Which of the following is a key advantage of using MPI in parallel computing?
What is the main drawback of the eager protocol?
What is the main drawback of the eager protocol?
Which of the following functions is used to determine the size of the message?
Which of the following functions is used to determine the size of the message?
Which function is used to free the communication?
Which function is used to free the communication?
You discover that your MPI program's performance is significantly degraded due to frequent small message transfers. Which MPI feature could be used to improve performance by combining multiple messages?
You discover that your MPI program's performance is significantly degraded due to frequent small message transfers. Which MPI feature could be used to improve performance by combining multiple messages?
Flashcards
Message Passing Interface (MPI)
Message Passing Interface (MPI)
An interface for efficient message passing, standard for communication in HPC centers.
MPI Header File
MPI Header File
Must be included to use MPI in a C++ program.
MPI_Init
MPI_Init
Initializes the MPI environment.
MPI_Finalize
MPI_Finalize
Signup and view all the flashcards
mpicxx
mpicxx
Signup and view all the flashcards
mpirun
mpirun
Signup and view all the flashcards
MPI Communicator
MPI Communicator
Signup and view all the flashcards
MPI_COMM_WORLD
MPI_COMM_WORLD
Signup and view all the flashcards
MPI_COMM_SELF
MPI_COMM_SELF
Signup and view all the flashcards
MPI_Comm_size
MPI_Comm_size
Signup and view all the flashcards
MPI_Comm_rank
MPI_Comm_rank
Signup and view all the flashcards
MPI_Send
MPI_Send
Signup and view all the flashcards
MPI_Recv
MPI_Recv
Signup and view all the flashcards
buffer
buffer
Signup and view all the flashcards
count
count
Signup and view all the flashcards
datatype
datatype
Signup and view all the flashcards
dest
dest
Signup and view all the flashcards
tag
tag
Signup and view all the flashcards
comm
comm
Signup and view all the flashcards
MPI_ANY_SOURCE, MPI_ANY_TAG
MPI_ANY_SOURCE, MPI_ANY_TAG
Signup and view all the flashcards
MPI_Ssend
MPI_Ssend
Signup and view all the flashcards
MPI_Bsend
MPI_Bsend
Signup and view all the flashcards
MPI_Isend
MPI_Isend
Signup and view all the flashcards
MPI_Wait
MPI_Wait
Signup and view all the flashcards
MPI_Test
MPI_Test
Signup and view all the flashcards
Eager protocol
Eager protocol
Signup and view all the flashcards
MPI process
MPI process
Signup and view all the flashcards
Group
Group
Signup and view all the flashcards
Communicator
Communicator
Signup and view all the flashcards
Rank
Rank
Signup and view all the flashcards
Study Notes
- Parallel Algorithms and Programming - Introduction to MPI
- MPI stands for “Message Passing Interface”
Outline
- Message Passing Interface (MPI)
- Example: Hello MPI world
- Point-to-Point communication
- Blocking send and receive
- Variants of send and receive
- Non-blocking send and receive
- Status, Test & Probe
- Eager vs. Rendezvous protocol
- Brief wrap-up
MPI - Efficient Message Passing
- MPI is a standard for communication in HPC centers
- The website is https://www.mpi-forum.org/
- MPI exists for a variety of languages including: C/C++, Fortran, Julia, and Python
- This course will use C++
MPI - API
- MPI describes the API (application programming interface) which supports efficient communication
- MPI is not the implementation, there are different implementations, like Open MPI, MPICH and vendor-specific MPIs
- HPC centers provide a library/header file with a communications standard and special interconnects optimized for HPC tasks
MPI Setup
- Before you can use MPI in a program, include the mpi.h header file
#include <mpi.h>
- Before using MPI, initialize it with
MPI_Init
- After using MPI, shut it down with
MPI_Finalize
Compiling MPI Programs
- Since MPI is an API, programs need compiled with special flags
- MPI uses a special compiler wrapper and hides those flags
- When using C++ code, replace the C++ compiler with "mpicxx" to compile a file:
$ mpicxx hello_mpi_world.cpp -o hello_mpi_world
- The above command uses a specific compiler, sets the include path to include mpi.h, and links the MPI library during the linking step
- That “mpicxx” is platform specific, which could be “mpiCC”
Running MPI Programs
- MPI programs need to be executed with
mpirun
- You need to specify the number of parallel processes to run, such as:
$ mpirun -n 4 ./hello_mpi_world [possible arguments to the program]
- That command starts the executable with 4 parallel processes and "mpirun" stops after all 4 parallel processes stop running.
- Running MPI programs on larger compute clusters would be more challenging
- You need to write a batch jobfile to describe how the job looks as a scheduler gets the job file to decide when to execute it
MPI Communicators
- An MPI communicator is a handle that describes sets of MPI processes which can communicate via a communicator
- MPI provides two default communicators which include
MPI_COMM_WORLD
: All MPI processes of the current applicationMPI_COMM_SELF
: Contains only own process
// Provided by mpi.h
MPI_Comm MPI_COMM_WORLD;
MPI_Comm MPI_COMM_SELF;
- Each communicator also assigns each MPI process a unique rank
MPI Size and Rank
- The size of MPI_COMM_WORLD matches the number of MPI processes used to run the MPI program
int MPI_Comm_size(MPI_Comm comm, int *size)
- An MPI process has a unique rank within the communicator so that it belongs to the communicator: 0 < R < size
int MPI_Comm_rank(MPI_Comm comm, int *rank)
MPI Example - Hello World
- It initializes MPI, gets rank within MPI_COMM_WORLD, and prints rank
- It gets the number of ranks in the communicator, then shuts down MPI
Point-to-point Communication
- Blocking send and receive
- Variants of send and receive
- Non-blocking send and receive
- Status, Test & Probe
- Eager vs. Rendezvous protocol
Sending MPI Messages
- The
MPI_Send
command sends data from one rank to another
int MPI_Send(
const void* buffer, // pointer to buffer
int count, // number of elements of particular type
MPI_Datatype datatype, // type of elements in buffer
int dest, // destination rank
int tag, // tag for send (must match tag for receive)
MPI_Comm comm // communicator to use
)
MPI Datatype
- Predefined types include:
MPI_INT
,MPI_CHAR
,MPI_FLOAT
, andMPI_DOUBLE
- Datatype describes the data type of elements that should be sent
- It's important rather than sending a chunk of binary data to handle different storage formats such as little-endian or big-endian
- Custom datatypes can also be created
MPI Message Parameters
buffer
points to the start of data block that should be sentdatatype
refers to the type of elements in buffercount
then represents the number of elements in the buffer and is of the type specified in datatypedest
is the destination rank to send the data totag
is an identifier of the message and can be used at receiving rank to receive messages with a matching tagcomm
is the MPI communicator to use
Sending Example
const char *hello_world = "HELLO WORLD";
MPI_Send(
hello_world, // pointer to buffer
strlen(hello_world)+1, // number of elements of particular type
MPI_BYTE, // type of elements in buffer
3, // destination rank
123, // tag for send (must match tag for receive)
MPI_COMM_WORLD // communicator to use
);
Receiving MPI Messages
- The
MPI_Recv
command receives data from a particular rank, such as:
int MPI_Recv(
void* recv_buffer, // pointer to buffer to store data
int count, // max capacity of elements in buffer
MPI_Datatype datatype, // type of elements in buffer
int source, // destination rank
int tag, // tag for send (must match tag for receive)
MPI_Comm comm, // communicator to use
MPI_status *status // status information of message
)
buffer
,count
,datatype
are the same as before, but buffer points to the data location to write data to “source"source
is the number of the rank to receive data from orMPI_ANY_SOURCE
to receive data from any source- "tag" is an identifier of message, only messages that were sent with the matching tag are processed
MPI_ANY_TAG
can be specified to get messages independent to the tagcomm
is the MPI communicator to use- “status” gives more information about message (discussed later)
wildcards
- When receiving messages
MPI_ANY_SOURCE
andMPI_ANY_TAG
should be avoided! - Always try to clearly specify from which source you're expecting information because there are only a few cases where they are useful
MPI_INT Data Type
- The types include:
MPI_CHAR
- signed charMPI_SHORT
- signed short intMPI_INT
- signed intMPI_LONG
- signed long intMPI_UNSIGNED_CHAR
- unsigned charMPI_UNSIGNED SHORT
- unsigned short intMPI_UNSIGNED
- unsigned intMPI_UNSIGNED_LONG
- unsigned long intMPI_FLOAT
- floatMPI_DOUBLE
- doubleMPI_LONG_DOUBLE
- long doubleMPI_BYTE
- 1 ByteMPI_PACKED
- see MPI_Pack()
MPI_Send - Different Variants
MPI_Ssend
: Synchronous send, which only returns if the receive started- It is most straight-forward way to send data
MPI_Bsend
: Buffered send, where the user needs to specify a buffer- Buffer is used to temporarily store the data to be sent
- It may complete before receive started
MPI_Send
: Can either be eitherMPI_Ssend
ORMPI_Bsend
- Note, this is implementation depending because the internal buffer used if
MPI_Bsend
is used
- Note, this is implementation depending because the internal buffer used if
MPI_Rsend
: Ready send assumes that receiver is already ready
Ssend vs. Bsend
- Subtle difference
- Ssend waits until the receive started, which also ensures that source data can be overwritten after function returns as the message started to be processed by the recipient
- Bsend waits until the message is copied to buffer: then the function can return since the source data can be overwritten
- This means nothing more than the message is on the way, nor anything else
- The memory chunk to be sent can be overwritten in both cases
- See also https://iamsorush.com/posts/mpi-send-types/ for more examples
MPI_Isend Non-Blocking Message
- MPI variants: MPI_Isend, MPI_Issend, MPI_Ibsend, MPI_Irsend which work similar to previous versions
int MPI_Isend(
const void* buffer, // source buffer
int count, // number of elements to send
MPI_Datatype datatype, // type of elements
int dest, // destination rank
int tag, // tag to use
MPI_Comm comm, // communicator
MPI_Request *request // request handler
)
- This function returns non-blocking right away, and the buffer may not be modified until send was successful
MPI_Request Data Structure
- MPI_Request is a data structure that is filled in by operations.
MPI_Request mpi_request;
int MPI_Isend(
&mpi_request // request handle
)
- MPI_Request
- Needs to be writable until the operation is finished
- Can only be free'd after the operation finished
- Can be used to inquire about the status of the operation
Status Information
- Status information can be requested,
MPI_status
structure contains directly accessible information:status.MPI_SOURCE
: Source rank to receive data fromstatus.MPI_TAG
: Tag of the messagestatus.MPI_ERROR
: Error information
- It contains size information which needs to be queried.
int MPI_Get_count(
const MPI_Status *status, // status information
MPI_Datatype datatype, // datatype of the elements
int *count // number of elements for given datatype
)
- Count is not the number of bytes for all data, but the number of elements and depends on the data type
Testing Request Status
- A non-blocking action.
int MPI_Test(
MPI_Request *request, // input: pointer to request handler
int *flag, // output: flag showing whether request finished
MPI_Status *status // output: status information (optional)
)
- it allows to see whether a request is finished
- 0: False
- 1 or all other values: True
- “status” can be optionally requested
Message Probing
- Messages may be tested for availability with
MPI_Probe
:
int MPI_Probe (
int source, // source rank
int tag, // tag of message
MPI_Comm comm, // communicator to use
MPI_Status *status // status
)
- This function blocks until a message is available
- The status can be used to get information about the message size
- MPI_Iprobe is non-blocking
Console output of MPI
- MPI does not guarantee anything about the order of the console output messages, because it is not defined in MPI!
- This only worked for our particular MPI implementation, so the only way to ensure a particular order of printing messages is to receive the messages into 0-th rank and print them with the 0-th rank in the required order
- For this, all messages should be sent to Rank 0
Communication Protocols
- There are two different protocols of communicating messages, like Eager and Rendezvous
Eager Protocol
- Data is sent assuming the receiver can directly store it, but if the receiver isn't ready, it introduces delay
- Works well for small messages less than 64kB
- Might lead to overhead for large messages
Message Passing Interface (MPI) Terminology
- MPI process is an instance of a program to use MPI
- Group is a set of MPI processes
- Communicator is an ordered list of MPI processes in group
- Rank is a unique id of MPI process in an ordered list of communicator
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.