This project explores parallel implementations of the Sobel edge detection algorithm using multiple paradigms:
- MPI for distributed-memory CPU systems
- OpenMP for shared-memory CPU systems
- CUDA for GPU acceleration
- Hybrid MPI + OpenMP for node-level and core-level parallelism
The goal of this project is to analyze and compare parallel programming models for 2D image processing using Sobel edge detection.
We aim to:
- Apply and evaluate parallel strategies (MPI, OpenMP, CUDA)
- Compare execution performance across different architectures (multicore CPU vs GPU)
- Demonstrate hybrid CPU-based parallelism with MPI + OpenMP
We compute the image gradient magnitude using the Sobel operator, a common method for edge detection.
- MPI: Distribute image rows with boundary overlap, using
MPI_ScattervandMPI_Gathervfor data transfer. - OpenMP: Use
#pragma omp parallel forto parallelize row-wise Sobel computation. - CUDA: Launch a 2D grid of GPU threads for pixel-wise Sobel filtering using coalesced memory access and shared memory.
- Hybrid: Each MPI process handles a chunk of the image and applies OpenMP for multi-threaded processing within its chunk.
parallel-edge-detection/
├── cuda/ # CUDA implementation
├── data/ # Input images
├── hybrid/ # Hybrid MPI + OpenMP
├── include/ # Header files (e.g., stb_image)
├── mpi/ # MPI implementation
├── openmp/ # OpenMP implementation
├── output/ # Output images
├── README.md # Documentation
mpi/mpi_sobel.copenmp/omp_sobel.ccuda/cuda_sobel.cuhybrid/hybrid_sobel.c
Use the following commands to build each variant.
cd mpi
mpicc -std=c99 -O2 mpi_sobel.c -o mpi_sobel -lmcd openmp
gcc -fopenmp -std=c99 -O2 omp_sobel.c -o omp_sobel -lmcd hybrid
mpicc -fopenmp -std=c99 -O2 hybrid_sobel.c -o hybrid_sobel -lmcd cuda
nvcc cuda_sobel.cu -o cuda_sobelmpirun --mca btl self,vader -np 4 ./mpi_sobel ../data/input_2048.jpgexport OMP_NUM_THREADS=4
./omp_sobel ../data/input_2048.jpgexport OMP_NUM_THREADS=4
mpirun --mca btl self,vader -np 2 ./hybrid_sobel ../data/input_2048.jpg./cuda_sobel ../data/input_2048.jpgEach implementation includes a benchmarking script:
run_mpi_exp.shrun_omp_exp.shrun_cuda_exp.shrun_hybrid_exp.sh
To execute all:
bash run_mpi_exp.sh
bash run_omp_exp.sh
bash run_cuda_exp.sh
bash run_hybrid_exp.shreport.md: Summary- Output images for verification:
output_mpi.jpgoutput_omp.jpgoutput_cuda.jpgoutput_hybrid.jpg
- OpenMPI
- GCC with OpenMP
- CUDA Toolkit
stb_image.h,stb_image_write.h
To clean the workspace:
rm mpi/mpi_sobel openmp/omp_sobel cuda/cuda_sobel hybrid/hybrid_sobel\
mpi/*.log openmp/*.log cuda/*.log hybrid/*.log\
output/output_*.jpg