A C++ MPI-based parallel computing project demonstrating core parallel algorithms and communication patterns.
- Heat Diffusion -- Parallel 2D Jacobi stencil with row-wise decomposition across MPI ranks. Supports both blocking and non-blocking halo exchange.
- Matrix Multiplication -- Parallel row-partitioned matrix multiplication using
MPI_Scatterv/MPI_Gathervwith matrix broadcast.
- Blocking Exchange -- Parity-ordered
MPI_Send/MPI_Recvwith deadlock prevention - Non-blocking Exchange --
MPI_Isend/MPI_IrecvwithMPI_Waitall - Neighbor Exchange -- 1D and 2D exchange via
MPI_Sendrecv - Ring Communication -- Token passing around a ring of processes
- Pipeline Communication -- Value flowing through a chain of processes
- Deadlock Demo -- Demonstrates deadlock scenario and its fix
- Process Groups -- Splitting communicators via
MPI_Comm_split
- MPI Implementation -- MS-MPI (Windows), MPICH, or OpenMPI
- CMake >= 3.16
- C++17 compatible compiler (MSVC, GCC, Clang)
- Ninja (optional, recommended)
cmake -B build -G Ninja
cmake --build buildcmake -B build
cmake --build build --config Releasempirun -np <num_processes> ./parallel_grid [algorithm] [options]Note: On Windows with MS-MPI, use
mpiexecinstead ofmpirun.
Run without arguments to get an interactive menu:
mpirun -np 4 ./parallel_grid| Algorithm | Command | Options |
|---|---|---|
| Heat Diffusion | heat |
--grid <N> grid size (default 512), --iter <I> iterations (default 200), --nonblocking use non-blocking exchange |
| Matrix Multiplication | matmul |
--size <N> random NxN size (default 256), --verify verify against sequential |
| Both | both (default) |
Combines heat + matmul settings |
| Deadlock Demo | deadlock_demo |
No additional options |
| Ring Demo | ring |
No additional options |
| Pipeline Demo | pipeline |
No additional options |
# Heat diffusion on 256x256 grid, 100 iterations, 8 processes
mpirun -np 8 ./parallel_grid heat --grid 256 --iter 100
# Matrix multiplication 512x512 with verification
mpirun -np 4 ./parallel_grid matmul --size 512 --verify
# Non-blocking halo exchange
mpirun -np 4 ./parallel_grid heat --grid 512 --iter 200 --nonblocking
# Communication demo
mpirun -np 6 ./parallel_grid ring
## Output
- **Heat Diffusion** produces `heat_output.csv` containing the final temperature grid, suitable for visualization in Excel or Python.
- **Matrix Multiplication** prints timing results and optionally verifies correctness against a sequential implementation.
- All algorithms report wall-clock timing via the built-in `Timer` class.
## MPI Concepts Demonstrated
| Concept | MPI Functions Used |
|---|---|
| Data Decomposition | Row-wise partitioning of grids and matrices |
| Broadcast | `MPI_Bcast` |
| Scatter/Gather | `MPI_Scatterv`, `MPI_Gatherv` |
| Reduction | `MPI_Reduce` |
| Blocking Communication | `MPI_Send`, `MPI_Recv` |
| Non-blocking Communication | `MPI_Isend`, `MPI_Irecv`, `MPI_Waitall` |
| Send-Receive | `MPI_Sendrecv` |
| Process Groups | `MPI_Comm_split` |
| Synchronization | `MPI_Barrier` |