This repository contains an implementation of Cannon's algorithm for parallel matrix multiplication using the Message Passing Interface (MPI).
Cannon's algorithm is a distributed algorithm for matrix multiplication that efficiently distributes the computation across multiple processes in a 2D grid configuration. This implementation focuses on minimizing communication overhead while maximizing computational efficiency for large matrix multiplications.
- Parallel implementation of matrix multiplication using MPI
- Efficient 2D grid communicator setup for process organization
- Cyclic data distribution for load balancing
- Point-to-point communication for matrix block exchange
- Comprehensive benchmarking and performance analysis
- Comparison with serial implementation
This implementation was tested on an HPC cluster (Pronto) with varying matrix sizes (500×500 to 4000×4000) and process counts (1 to 64). Key findings include:
- Significant execution time reduction for large matrices compared to serial implementation
- Performance scaling up to 50+ GFLOPS for large matrices with 32-64 processes
- Optimal scalability observed up to 32 processes for 2000×2000 and 4000×4000 matrices
- Diminishing returns beyond optimal process count due to communication overhead
- C++ compiler with MPI support
- OpenMPI library
- Linux-based operating system (tested on OnDemand HPC cluster)
- Clone the repository:
git clone https://github.com/muzakker/mpi-cannon-matmul.git
cd mpi-cannon-matmul- Compile the code:
mpic++ -o cannon_matmul cannon_matmul.cpp- Run the program (replace N with matrix size and P with process count):
mpirun -np P ./cannon_matmul Ncannon_matmul.cpp: Main implementation of Cannon's algorithmserial_matmul.cpp: Serial implementation for comparisonscripts/: Testing and benchmarking scriptsfigures/: Performance visualization graphsresults/: Raw performance data
The implementation follows these key steps:
- Setup Phase: Creates a 2D grid communicator for process organization
- Data Distribution: Distributes matrix blocks across processes
- Initial Alignment: Shifts matrix blocks to their initial positions
- Computation Phase:
- Each process performs local matrix multiplication
- Cyclic shifting of matrices along rows and columns
- Repeated computation and communication steps
- Result Collection: Gathers partial results to form the final matrix
- Parallel matrix multiplication using MPI significantly outperforms serial implementation for large matrices
- The optimal number of processes depends on the matrix size and hardware configuration
- Communication overhead becomes a limiting factor in scalability beyond certain process counts
- For best performance, matrix sizes should be balanced against the number of processes
MIT
Md Muzakker Hossain

