Download presentation
Presentation is loading. Please wait.
1
N-Body Gravitational Simulations
Joshua White Patrick Loftus
2
Overview Purpose and types of n-body simulations
Gravitational simulations Derivation of direct gravitational algorithm HOT n-body simulation algorithm Derivation of tree-reduction algorithm Results Conclusions Questions
3
Purpose and types of n-body simulations
A simulation of a dynamical system of particles Usually under the effects of a physical force (e.g., gravity, Coulomb force, etc.) Used to model interactions between bodies and forces Used over scales from the absolute smallest possible (quantum many-body simulations) to the absolute largest possible (cosmological evolution simulations) Common applications: galaxy formation and evolution, star cluster interactions, subatomic and quantum interactions, thermodynamic fluid simulations We will focus on gravitational simulations, but the principles are generally applicable to all types of n-body simulations
4
Gravitational simulations
32,768 solar mass bodies 1.8 million solar mass central core 1 billion year simulation time Video source: Wikimedia Commons
5
Gravitational simulations
Newtonβs Law of Universal Gravitation The force between two objects is proportional to the product of their masses and inversely proportional to the square of the distance between them Formally: πΉ 12 =β πΉ 21 =πΊ π 1 π π π Where the Universal Gravitational Constant, G = x m3/kg*s2 Image source: Wikimedia Commons
6
Gravitational simulations
For interactions involving multiple bodies, the resultant force acting on a body is equal to the sum of the contributions from all other bodies. πΉ πππ = π π π π = π,π πΊ π π π π π ππ π ππ The resultant acceleration of the body can be found by canceling its mass contribution, yielding: π π = πΊ π π π ππ π ππ
7
Gravitational simulations
For direct simulation, the acceleration is evaluated at discrete time steps, then integrated. π₯ π‘ = π‘ 0 π‘ π π₯ π‘ β
π‘ ππ‘ Given velocity vx, initial position x0 and treating all variables except t as constant over a single time step, the above can be directly integrated. π₯ π‘ = π₯ 0 + π£ π₯ t π π₯ π‘ 2 The velocity is then updated for the next iteration. π£ π₯ π‘ = π£ 0 + π π₯ π‘ Yields time complexity of πͺ( π 2 )
8
Derivation of direct gravitational algorithm
The βheartβ of algorithm Determine instantaneous acceleration of each body Direct integration to determine position at next time step Write positions to file Selection of OpenMP Necessity to synchronize at each step Excessive message passing between processors/threads Use of OpenMP βparallel forβ pragma creates implicit barrier after each iteration Time complexity πͺ( π 2 π )
9
Derivation of direct gravitational algorithm
The βheartβ of the algorithm
10
Derivation of direct gravitational algorithm
Updating the acceleration vectors
11
Derivation of direct gravitational algorithm
Updating the position and velocity vectors
12
HOT n-body simulation algorithm
Breaks the universe into octants using a hashed oct-tree Interactions with non-adjacent octants are βsmoothedβ using systemβs center of mass Assumes fixed universe size Tree must be rebuilt for each body Load balancing issues Synchronization issues Time complexity πͺ(π log π )
13
HOT n-body simulation algorithm
Universe is partitioned into octants (quadrants shown for clarity) Each octant repartitioned until each contains one body Center of mass for partition calculated Image source: Burtscher and Pingali, 2011
14
HOT n-body simulation algorithm
Interaction with non-adjacent regions calculated based on center of mass Interactions with bodies in adjacent regions calculated directly Preserves resolution of short distance interactions Problematic because tree is dependent on fixed universe size Image source: Burtscher and Pingali, 2011
15
Derivation of tree-reduction algorithm
Resultant force points to center of mass Magnitude determined by combined masses of bodies Recall π π = πΊ π π π ππ π ππ Center of mass given by π ππ = 1 π π‘ππ‘ π π π π π Thus, large-scale behavior can be approximated using center of mass of the entire cluster
16
Derivation of tree-reduction algorithm
By sacrificing small-scale resolution, the number of trees per iteration can be reduced to one Using a binary reduction, the center of mass of the entire cluster is calculated Each body removes its contribution to mass total and center of mass when calculating force interaction Has the advantage of making no assumptions about overall universe size Not suitable where fine resolution interactions are required, but preserves large-scale behavior of system Time complexity πͺ(π+ log π )
17
Derivation of tree-reduction algorithm
Tree reduction to determine center of mass
18
Derivation of tree-reduction algorithm
Updating acceleration, position, and velocity vectors
19
Results N-body simulation results Timing results
What are our bodies doing and why are they behaving that way? Timing results Was the tree algorithm significantly faster than the direct algorithm? As we added threads, did we see speedup for both algorithms?
20
N-body simulation results
Direct algorithm simulation Tree algorithm simulation
21
N-body simulation results
Direct algorithm
22
N-body simulation results
Tree algorithm
23
Barnes-hut approximation
24
White-loftus approximation
25
Timing results
26
Timing results: Direct algorithm
27
Timing results: Tree algorithm
28
Conclusions Data confirms that tree algorithm is exponentially faster than the direct algorithm Both algorithms showed significant speedup when ported to OpenMP N-body simulations are fun!
29
2048 bodies!
30
References An efficient CUDA implementation of the tree-based Barnes Hut n-body algorithm. Martin Burtscher and Keshav Pingali. In GPU Computing Gems Emerald Edition, pages Morgan Kaufmann, 2011. 2HOT: an improved parallel hashed oct-tree n-body algorithm for cosmological simulation. Michael S. Warren. In SC '13 Proceedings of the International Conference on High Performance Computing, Networking, Storage and Analysis. Article No. 72. A parallel hashed oct-tree n-body algorithm. Michael S. Warren. In Proceedings of the 1993 ACM/IEEE conference on Supercomputing. Pages
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.