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.

  1. The simulation box is divided into cubic cells of side length . Each atom is hashed to a 1D cell index .
  2. Atoms are sorted by cell ID using CUB Radix Sort.
  3. A lookup table (cell_start, cell_end) is generated to map cell IDs to start/end indices in the sorted atom array.
  4. 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 ().

  1. Half-Kick:
  2. Drift:
  3. Compute Forces:
  4. Half-Kick:

Resources:

Github