This repository contains materials for the High-Performance Computing (HPC) course, focusing on hands-on labs and talks about Parallel Programming using the MPI (Message Passing Interface) package.
Follow these steps to set up the environment for working with MPI in your project:
-
Create a Project: Create an empty project or console application in your preferred Integrated Development Environment (IDE).
-
Configure Project Properties:
- Navigate to the project properties and access the Configuration Properties for C/C++.
- Under "Additional Include Directories," add the path:
C:\Program Files (x86)\Microsoft SDKs\MPI\Include
.
-
Configure Linker Properties:
- Still, in project properties, go to the Linker section.
- Under "Additional Library Directories," add the path:
C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64
orC:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x86
based on your system architecture.
-
Configure Linker Input:
- Inside the Linker section, navigate to Input.
- Under "Additional Dependencies," add:
msmpi.lib
.
-
Apply Changes:
- Press Apply and then OK to save the changes.
-
Write Your Code:
- Create or open a CPP file within the source files folder of your project.
- Write your MPI code in the CPP file.
-
Build the Solution:
- Build the solution from the Build tab in your IDE.
-
Run the Executable:
- Navigate to the executable file path in your project directory.
- Open Command Prompt (cmd) in that directory.
- Run the following command to execute the program:
Replace "Project_Name" with the name of your executable file.
mpiexec "Project_Name"
Here are some of the most commonly used MPI functions along with explanations for their parameters:
-
MPI_Init
- Function: Initializes the MPI execution environment.
- Parameters:
argc
: Pointer to the number of arguments.argv
: Pointer to the argument vector.
-
MPI_Finalize
- Function: Terminates MPI execution environment.
- Parameters: None.
-
MPI_Comm_size
- Function: Determines the size of a communicator.
- Parameters:
comm
: Communicator (group of processes).size
: Pointer to an integer where the size of the communicator will be stored.
-
MPI_Comm_rank
- Function: Determines the rank of the calling process in the communicator.
- Parameters:
comm
: Communicator (group of processes).rank
: Pointer to an integer where the rank of the calling process will be stored.
-
MPI_Send
- Function: Sends a message from one process to another.
- Parameters:
buf
: Pointer to the send buffer.count
: Number of elements in the send buffer.datatype
: Data type of elements in the send buffer.dest
: Rank of the destination process.tag
: Message tag (user-defined).
-
MPI_Recv
- Function: Receives a message from another process.
- Parameters:
buf
: Pointer to the receive buffer.count
: Number of elements in the receive buffer.datatype
: Data type of elements in the receive buffer.source
: Rank of the source process.tag
: Message tag (user-defined).status
: Status object to receive status information.
-
MPI_Isend
- Function: Initiates a non-blocking send operation.
- Parameters:
buf
: Pointer to the send buffer.count
: Number of elements in the send buffer.datatype
: Data type of elements in the send buffer.dest
: Rank of the destination process.tag
: Message tag (user-defined).comm
: Communicator (group of processes).request
: Pointer to a request object that will be created and used to manage the communication.
-
MPI_Irecv
- Function: Initiates a non-blocking receive operation.
- Parameters:
buf
: Pointer to the receive buffer.count
: Number of elements in the receive buffer.datatype
: Data type of elements in the receive buffer.source
: Rank of the source process.tag
: Message tag (user-defined).comm
: Communicator (group of processes).request
: Pointer to a request object that will be created and used to manage the communication.
-
MPI_Scatter
- Function: Scatters data from the root process to all processes in a communicator.
- Parameters:
sendbuf
: Pointer to the send buffer (root process).sendcount
: Number of elements to send from the send buffer (root process).sendtype
: Data type of elements in the send buffer (root process).recvbuf
: Pointer to the receive buffer (all processes).recvcount
: Number of elements to receive in the receive buffer (all processes).recvtype
: Data type of elements in the receive buffer (all processes).root
: Rank of the root process.comm
: Communicator (group of processes).
-
MPI_Gather
- Function: Gathers data from all processes to the root process in a communicator.
- Parameters:
sendbuf
: Pointer to the send buffer (all processes).sendcount
: Number of elements to send from the send buffer (all processes).sendtype
: Data type of elements in the send buffer (all processes).recvbuf
: Pointer to the receive buffer (root process).recvcount
: Number of elements to receive in the receive buffer (root process).recvtype
: Data type of elements in the receive buffer (root process).root
: Rank of the root process.comm
: Communicator (group of processes).
-
MPI_Reduce
- Function: Performs a reduction operation on data distributed across processes.
- Parameters:
sendbuf
: Pointer to the send buffer.recvbuf
: Pointer to the receive buffer.count
: Number of elements in the send buffer.datatype
: Data type of elements in the send buffer.op
: Reduction operation to be performed.root
: Rank of the root process.comm
: Communicator (group of processes).
-
MPI_Bcast
- Function: Broadcasts a message from the root process to all other processes in a communicator.
- Parameters:
buffer
: Pointer to the buffer containing the data to be broadcast.count
: Number of elements in the buffer.datatype
: Data type of elements in the buffer.root
: Rank of the root process.comm
: Communicator (group of processes).