Presentation is loading. Please wait.

Presentation is loading. Please wait.

N-Body Gravitational Simulations

Similar presentations


Presentation on theme: "N-Body Gravitational Simulations"β€” Presentation transcript:

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


Download ppt "N-Body Gravitational Simulations"

Similar presentations


Ads by Google