{"slug": "show-hn-real-time-n-body-tree-code-in-cuda", "title": "Show HN: Real-time n-body tree code in CUDA", "summary": "A developer released a real-time n-body simulation using the Barnes-Hut algorithm on GPU, implemented in CUDA C++ and OpenGL, scaling to millions of particles on an NVIDIA RTX 500 Ada Laptop GPU. The open-source project runs on Ubuntu 22.04 with CUDA Toolkit 12.9 and supports interactive camera controls and octree visualization.", "body_md": "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.\n\nThe 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\n\n```\nsudo apt install build-essential libgl1-mesa-dev libsdl2-dev libglew-dev\n```\n\nDetailed installation instructions for the CUDA Toolkit can be found [here](https://developer.nvidia.com/cuda-downloads).\n\nTo build the project for a GPU with compute capability `xy`\n\n, run\n\n```\nmake CUDA_ARCHS=\"xy\"\n```\n\nMore info on compute capability versioning [here](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#gpu-feature-list). If not specified, the program will be built for the following architectures: `50 60 70 75 80 89`\n\n.\n\nBuild files will be placed under `build/`\n\n, running\n\n```\nmake clean\n```\n\nwill remove the `build/`\n\ndirectory but keep the executable.\n\nThe program can be executed by running\n\n```\n./main\n```\n\nDrag to orbit the camera around the origin, and scroll to zoom. Pressing `o`\n\ntoggles the octree visualization, `space`\n\npauses/resumes the simulation, `1`\n\n, `2`\n\nand `3`\n\nspawn the particles in different initial configurations.\n\n| Basic visualization | Octree visualization |\n\n| Self-gravitating disk of 262,144 particles | Cold collapse of uniform sphere |\n\n| Disk of 524,288 particles running at ~37 FPS (θ=0.75) | Two disks of 262,144 particles each running at ~30 FPS (θ=0.75) |\n\n| Total energy for 32,768 particles | Relative acceleration error for 32,768 particles |\n\n| Execution time of a single step for θ=0.75 | Scalability for different values of θ (log-log) |\n\n-\nTero 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.\n\n-\nRobin 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.\n\n[https://doi.org/10.1145/3659914.3659928](https://doi.org/10.1145/3659914.3659928) -\nJeroen 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:\n\n[https://doi.org/https://doi.org/10.1016/j.jcp.2011.12.024](https://doi.org/https://doi.org/10.1016/j.jcp.2011.12.024)", "url": "https://wpnews.pro/news/show-hn-real-time-n-body-tree-code-in-cuda", "canonical_source": "https://github.com/lechebs/nbody", "published_at": "2026-07-10 15:47:30+00:00", "updated_at": "2026-07-10 16:05:29.763225+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "ai-research", "ai-infrastructure", "developer-tools"], "entities": ["NVIDIA", "CUDA", "OpenGL", "Ubuntu", "Tero Karras", "Robin Cazalbou", "Jeroen Bédorf", "Simon Portegies Zwart"], "alternates": {"html": "https://wpnews.pro/news/show-hn-real-time-n-body-tree-code-in-cuda", "markdown": "https://wpnews.pro/news/show-hn-real-time-n-body-tree-code-in-cuda.md", "text": "https://wpnews.pro/news/show-hn-real-time-n-body-tree-code-in-cuda.txt", "jsonld": "https://wpnews.pro/news/show-hn-real-time-n-body-tree-code-in-cuda.jsonld"}}