Skip to content

lechebs/nbody

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

101 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time CUDA Accelerated Barnes-Hut N-Body Simulation

An implementation of the Barnes-Hut algorithm, running in real-time on the GPU, developed using CUDA C++ and OpenGL, which scales to systems of few million particles on a NVIDIA RTX 500 Ada Laptop GPU.

Prerequisites

The program was developed and tested on Ubuntu 22.04 LTS using the CUDA Toolkit 12.9, SDL2 and OpenGL 4.3 core. The basic dependencies can be installed under Ubuntu by running

sudo apt install build-essential libgl1-mesa-dev libsdl2-dev libglew-dev

Detailed installation instructions for the CUDA Toolkit can be found here.

Building

To build the project for a GPU with compute capability xy, run

make CUDA_ARCHS="xy"

More info on compute capability versioning here. If not specified, the program will be built for the following architectures: 50 60 70 75 80 89.

Build files will be placed under build/, running

make clean

will remove the build/ directory but keep the executable.

Usage

The program can be executed by running

./main

Drag to orbit the camera around the origin, and scroll to zoom. Pressing o toggles the octree visualization, space pauses/resumes the simulation, 1, 2 and 3 spawn the particles in different initial configurations.

Gallery

Basic visualization Octree visualization
Self-gravitating disk of 262,144 particles Cold collapse of uniform sphere
Disk of 524,288 particles running at ~37 FPS (θ=0.75) Two disks of 262,144 particles each running at ~30 FPS (θ=0.75)

2,097,152 particles at ~150ms per step (θ=0.6)

4,194,304 particles at ~430ms per step (θ=0.6)

Plots

Total energy for 32,768 particles Relative acceleration error for 32,768 particles
Execution time of a single step for θ=0.75 Scalability for different values of θ (log-log)

Bibliography

  • Tero Karras. 2012. Maximizing parallelism in the construction of BVHs, octrees, and k-d trees. In Proceedings of the Fourth ACM SIGGRAPH / Eurographics conference on High-Performance Graphics (EGGH-HPG'12). Eurographics Association, Goslar, DEU, 33–37.

  • Robin Cazalbou, Florent Duchaine, Eric Quémerais, Bastien Andrieu, Gabriel Staffelbach, and Bruno Maugars. 2024. Hybrid Multi-GPU Distributed Octrees Construction for Massively Parallel Code Coupling Applications. In Proceedings of the Platform for Advanced Scientific Computing Conference (PASC '24). Association for Computing Machinery, New York, NY, USA, Article 14, 1–11. https://doi.org/10.1145/3659914.3659928

  • Jeroen Bédorf, Evghenii Gaburov, and Simon Portegies Zwart. 2012. A sparse octree gravitational N-body code that runs entirely on the GPU processor. Journal of Computational Physics 231, 7 (2012), 2825–2839. DOI:https://doi.org/https://doi.org/10.1016/j.jcp.2011.12.024

About

A real-time CUDA accelerated Barnes-Hut tree code for the n-body problem using C++ and OpenGL.

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Contributors