This project implements a Convolutional Neural Network (CNN) in C++ using multiple parallelization strategies:
- Sequential
- OpenMP
- MPI
- Hybrid (MPI + OpenMP)
The network is trained and evaluated on the MNIST dataset provided in CSV format.
parallel-CNN/
│
├── dataset/ # Contains mnist.zip which includes mnist_train.csv and mnist_test.csv
├── Sequential/ # Sequential C++ implementation
├── OpenMP/ # OpenMP parallelized CNN
├── MPI/ # MPI parallelized CNN
├── Hybrid/ # MPI + OpenMP hybrid CNN
└── README.md
- C++ compiler:
- g++ with OpenMP support
- mpic++ (for MPI and Hybrid)
- Dataset:
- Located in the dataset/ directory as a ZIP file
The dataset is provided as a ZIP archive: dataset/mnist.zip.
Before running any version of the code, unzip the dataset as follows:
cd dataset
unzip mnist.zip
cd ..This will extract the following required files:
dataset/mnist_train.csvdataset/mnist_test.csv
cd Sequential
g++ cnn.cpp -o cnn_seq
./cnn_seqcd OpenMP
g++ -fopenmp cnn.cpp -o cnn_omp
./cnn_ompTo control the number of threads:
export OMP_NUM_THREADS=4cd MPI
mpic++ cnn.cpp -o cnn_mpi
mpirun -np 4 ./cnn_mpiReplace 4 with the desired number of MPI processes.
cd Hybrid
mpic++ -fopenmp cnn.cpp -o cnn_hybrid
mpirun -np 2 ./cnn_hybridTo control OpenMP threads per MPI process:
export OMP_NUM_THREADS=4
mpirun -np 2 ./cnn_hybridAll versions of the program will print:
- Training time
- Testing time
- Accuracy
- Confusion matrix
- RMSE