Submitted under: CDAC CINE, IIT Guwahati Campus
Contributors: Partha Pratim Das, Manash Das
This project implements a classic N-Body gravitational simulation to demonstrate the power of High Performance Computing (HPC) using GPU acceleration. We compare a baseline sequential CPU implementation (NumPy) against a parallel GPU implementation (CuPy) to measure speedup and scalability.
This work addresses the
- Scientific Correctness: Uses Newton's Law of Gravitation with softening.
-
Dual Implementation:
- CPU: Sequential, vectorized implementation using NumPy.
- GPU: Massive parallel implementation using CuPy (CUDA).
-
Benchmarking: Rigorous performance analysis across varying particle counts (
$N$ ). - Visualization: Speedup curves, scalability plots, and particle animations.
- Portability: Designed to run seamlessly on Google Colab and local implementations with NVIDIA GPUs.
- Data Parallelism: Distributing particle force calculations across thousands of GPU cores.
- Memory Bandwidth vs. Compute Bound: Analyzing the transfer overhead vs. computational gain.
- Amdahl's Law: Understanding the limits of parallel speedup.
- Vectorization: Efficient array operations in Python.
HPC-NBody-Simulation/
├── notebooks/ # Main logical notebook for benchmarking & visualization
├── src/ # Python source modules for N-Body logic
│ ├── cpu_nbody.py # NumPy implementation
│ └── gpu_nbody.py # CuPy implementation
├── data/ # Directory for initial conditions (auto-generated)
├── results/ # Generated plots and animations
├── report/ # Project report and documentation
└── requirements.txt # Python dependencies
- Upload the entire
HPC-NBody-Simulationfolder to your Google Drive. - Open
notebooks/nbody_cpu_vs_gpu.ipynbin Google Colab. - Mount Google Drive.
- Change the runtime type to GPU.
- Run all cells to execute benchmarks and generate results.
Prerequisites: NVIDIA GPU, CUDA Toolkit installed.
-
Clone the repository:
git clone <repository-url> cd HPC-NBody-Simulation
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
Note: You may need to install the specific CuPy version for your CUDA toolkit (e.g.,
pip install cupy-cuda12x). -
detailed steps are in the notebook.
- Console output showing execution times for different
$N$ . - Plots in
results/:cpu_time_vs_particles.pnggpu_time_vs_particles.pngspeedup_curve.png
-
nbody_simulation.gif: Animation of the planetary motion.
Developed for academic evaluation.