Custom Hybrid CPU/GPU Molecular Dynamics Engine
A high-performance Molecular Dynamics (MD) engine written in C++ and CUDA. It uses a hybrid architecture where bond/angle forces are calculated on the CPU (OpenMP) and non-bonded interactions (Lennard-Jones + Coulomb) are accelerated on the GPU.
Features:
Forces are computed independently on CPU/GPU and summed into a shared force array before the integration step.
GPU Neighbor Searching (Cell-Linked List):
To avoid the cost of checking every atom pair, I used a spatial hashing algorithm entirely on the GPU.
- The simulation box is divided into cubic cells of side length . Each atom is hashed to a 1D cell index .
- Atoms are sorted by cell ID using CUB Radix Sort.
- A lookup table (cell_start, cell_end) is generated to map cell IDs to start/end indices in the sorted atom array.
- For every atom, the kernel searches only the 27 adjacent cells (3x3x3 block). Neighbors within are stored in a fixed-width adjacency list per atom.
Equations:
1. Equations of Motion - Langevin Dynamics
The engine uses Langevin Dynamics instead of standard Newtonian physics (). This simulates a system connected to a heat bath (thermostat) by adding friction and random thermal noise.
2. Non-Bonded Interactions (GPU)
Calculated between all pairs of atoms (excluding bonded neighbors) that fall within the cutoff radius ().
A. Lennard-Jones Potential
B. Coulomb Potential (Electrostatics)
3. Bonded Interactions (CPU)
A. Harmonic Bonds (2-Body)
B. Harmonic Angles (3-Body)
4. Integration Scheme (Velocity Verlet)
The engine solves these differential equations using a discrete time step ().
- Half-Kick:
- Drift:
- Compute Forces:
- Half-Kick:
Resources:
- Used this as a starting point: https://youtu.be/ChQbBqndwIA?si=14Vq-WGgh8yWk7DQ
- C++: https://www.learncpp.com/
- Langevin Dynamics: https://en.wikipedia.org/wiki/Langevin_dynamics
- CUDA basics: https://youtu.be/xwbD6fL5qC8?si=ivaTzz3BVbgJdFsF