Efficient solution of the n-body problem

41
Honor Thesis Presentation Mike Bantegui, Hofstra University Advisor: Dr. Xiang Fu, Hofstra University EFFICIENT SOLUTION OF THE N- BODY PROBLEM

description

Efficient solution of the n-body problem. Honor Thesis Presentation Mike Bantegui, Hofstra University Advisor: Dr. Xiang Fu, Hofstra University. Outline. The N-Body Problem Computational challenges Results Existing work IGS Framework Extensions. The n-body problem. - PowerPoint PPT Presentation

Transcript of Efficient solution of the n-body problem

Page 1: Efficient solution of the n-body problem

Honor Thesis Presentation

Mike Bantegui, Hofstra University

Advisor: Dr. Xiang Fu, Hofstra University

EFFICIENT SOLUTION OF THE N-BODY PROBLEM

Page 2: Efficient solution of the n-body problem

OUTLINE• The N-Body Problem

• Computational challenges

• Results

• Existing work

• IGS Framework

• Extensions

Page 3: Efficient solution of the n-body problem

THE N-BODY PROBLEM• Given mass, position and velocities of N bodies at some time t

• Know pairwise forces using

• Determine evolution of the system of bodies

• Used to study Stellar Dynamics

Page 4: Efficient solution of the n-body problem

THE N-BODY PROBLEM CONT.• Must integrate 3N coupled nonlinear second order ordinary differential equations

• Not analytically possible except for N = 2

• Must resort to numerical methods

Page 5: Efficient solution of the n-body problem

CANDIDATE NUMERICAL SOLUTION• Set

• While

• For each body, evaluate total force

• Integrate position, velocity of each body over small time

• Set

Page 6: Efficient solution of the n-body problem

FORCE EVALUATION STEP• For i = 0 … N – 1

• For j = I + 1 … N – 1

• Compute pairwise gravity between body and

Page 7: Efficient solution of the n-body problem

EXAMPLE FORCE EVALUATION

Page 8: Efficient solution of the n-body problem

TIME COMPLEXITY• Total steps =

• Force evaluations =

• Integration =

• Overall complexity =

Page 9: Efficient solution of the n-body problem

ISSUES WITH CANDIDATE SOLUTION• Very slow due to quadratic behavior of force evaluation

• Requires evaluations for

• Constant time steps could miss near-collisions

• Force evaluation not obviously parallelizable

Page 10: Efficient solution of the n-body problem

“GEOMETRIC TRICK” FOR PARALLELIZATION

Page 11: Efficient solution of the n-body problem

“GEOMETRIC TRICK” FOR PARALLELIZATION

Page 12: Efficient solution of the n-body problem

“GEOMETRIC TRICK” FOR PARALLELIZATION

Page 13: Efficient solution of the n-body problem

TIME COMPLEXITY OF GEOMETRIC TRICK• (Triangular portion)

• (Block portion)

Page 14: Efficient solution of the n-body problem

ISSUES WITH GEOMETRIC TRICK• Parallelizes poorly beyond P > 2 using OpenMP

• Use naïve force evaluation algorithm for P > 2:

• For i = 0 … N – 1

• For j = 0 … N – 1

• if i != j

• Add Force due to acting on onto

• Twice as much work, for scalability

Page 15: Efficient solution of the n-body problem

NAÏVE FORCE EVALUATION SPEEDUP

1 3 5 7 9 11 13 150

100

200

300

400

500

600

700

800

900

1000

1

3

5

7

9

11

13

15

Naïve Parallelization Scaling

CPU Time

Speedup

Theoretical

Threads

CPU

Tim

e (m

illis

econ

ds)

Spee

dup

Page 16: Efficient solution of the n-body problem

HANDLING CLOSE ENCOUNTERS• Keep track of a minimum collision timescale for each body:

• Use to vary when integrating

• Number of steps taken is no longer predictable

• Support higher order PEC-type integrators (Leapfrog, 4 th and 6th order Hermite)

• Allows dramatic increase in step size for similar error

Page 17: Efficient solution of the n-body problem

A MORE EFFICIENT WAY OF EVALUATING FORCE• Treat clustered system as point-like body

• Force between cluster and a body is given by total mass at center of mass

Page 18: Efficient solution of the n-body problem

EXAMPLE OF CLUSTERING BODIES

Page 19: Efficient solution of the n-body problem

HIERARCHICAL FORCE EVALUATION • Apply the clustering principle recursively

• Consider sub-clusters within a cluster

• Refine force evaluation via sub-clusters instead of main cluster

Page 20: Efficient solution of the n-body problem

CLUSTERING ALGORITHM• Node Cluster(bodies, min_bound, max_bound)

• If bodies.size == 0

• return null

• if bodies.size == 1

• return node containing body

• Collect bodies into spatial groups

• For each group

• Cluster(group.bodies, group.min_bound, group.max_bound)

• Compute first order multipole expansion, passing up tree

• return node containing groups

Page 21: Efficient solution of the n-body problem

METHODS OF SPATIAL SUBDIVISION• Octree Barnes-Hut Algorithm

• K-D tree Stadel Algorithm

• Other choices possible

• Time to build tree is

• Parallelization opportunity available on recursive calls to Cluster

Page 22: Efficient solution of the n-body problem

FORCE EVALUATION ALGORITHM• TreeWalk(body)

• For each branch in the tree

• If branch is leaf

• If branch.body != body

• Compute force of branch.body on body

• Else

• Compute distance between branch and body

• If body is well separated from cluster

• Compute force of branch on body

• Else

• branch.TreeWalk(body)

Page 23: Efficient solution of the n-body problem

FORCE EVALUATION ALGORITHM, CONT• Call TreeWalk for each body:

• For i = 0 .. N – 1

• TreeWalk()

Page 24: Efficient solution of the n-body problem

SEPARATION CRITERIA• Body is well separated when acceptance criteria met:

• Accept the approximation when clusters compact, body is far away

• allows tuning for performance vs. accuracy

• Alternative criteria available

Page 25: Efficient solution of the n-body problem

TIME COMPLEXITY OF TREE WALK• For single body walking a node of size N:

• For N bodies:

Page 26: Efficient solution of the n-body problem

OVERVIEW OF HIERARCHICAL ALGORITHM• Build tree in steps

• Walk tree in steps

• For N = 65536, brute-force pairwise requires evaluations

• Hierarchical algorithm can do same in evaluations

• Very easily parallelization

Page 27: Efficient solution of the n-body problem

PARALLELIZING TREE METHODS

1 3 5 7 9 11 13 150

100

200

300

400

500

600

700

800

1

3

5

7

9

11

13

15

Octree Parallelization Scaling

CPU Time

Speedup

Theoretical

Threads

Tim

ing

(mill

isec

onds

)

Spee

dup

Page 28: Efficient solution of the n-body problem

SCALING TO LARGE N, OCTREE

Page 29: Efficient solution of the n-body problem

SCALING TO LARGE N, KD-TREE

Page 30: Efficient solution of the n-body problem

SCALING TO LARGE N, BRUTE FORCE

Page 31: Efficient solution of the n-body problem

BRUTE FORCE VS TREE METHODS

Page 32: Efficient solution of the n-body problem

ENERGY ERRORS

Page 33: Efficient solution of the n-body problem

ENERGY ERRORS CONT.

Page 34: Efficient solution of the n-body problem

RELATED WORK• nbody1 – nbody6, Sverre Aarseth

• ACS toolkit, Jun Makino and Piet Hut

• Grav-Sim, Mark Ridler

• Gravit, Gerald Kaszuba et al.

Page 35: Efficient solution of the n-body problem

THE PROPOSED FRAMEWORK• Component based Interactive Gravitational Simulator

• CoreIGS – Core simulation library

• CmdIGS – Command line driven interface

• VisIGS – Interactive visualizer

Page 36: Efficient solution of the n-body problem

SOFTWARE ARCHITECTUREAccelerator

Integrator

System

Model

+Position : Vector+Velocity : Vector

PhasePoint

+Time : double+Acceleration : Vector+Jerk : Vector

WorldPoint

+Mass : double+Potential : double+Radius : double

Graviton

+CollisionTimescaleSq : double+NextTime : double+Start : WorldPoint+End : WorldPoint

Body

-Bodies : Body-N : int-Mass : double-Softening : double-Dynamics

NBodySystem

+Kinetic : double+Potential : double+CenterOfMass : Vector+CenterOfMomentum : Vector+AngularMomentum : Vector+AngularVelocity : Vector

Dynamics

1 1

1

*

-Bodies : PhasePoint-N : int-Mass : double-Dynamics : Dynamics

Snapshot1*

11

#Fill() : void

Model

SphericalModel PlummerModel

DiskModel

CompositeModel

1

1..*

+Predict() : void+Correct() : void

Integrator

EulerIntegrator

HermiteIntegrator

LeapfrogIntegrator

SymplecticEuler

EulerTrapezoidIntegrator

+Branches : Graviton+Quadrupole : Tensor

Node1

0..*

#Branch() : Node

#Root : Node-Theta : double-BranchSize : int-LeafSize : int

Tree1

0..1

#Branch() : Node

Octree

#Branch() : Node

KDTree

-System : NBodySystem-Stepper : Integrator-Accelerator : Tree-Time : double-NextTime : double-Steps : int

Simulator

Page 37: Efficient solution of the n-body problem

PROJECT STATS• Open Source – Available at IGS.codeplex.com

• 3+ years development

• 5670 lines of code

• 65 .cpp, .h files

• 107 subversion revisions

• 8 development iterations

• Many failures before success!

Page 38: Efficient solution of the n-body problem

EXTENSIONS• Individual time steps

• Distributed simulations using MPI

• Higher order integrators

• Command interface for the visualizer

• Other spatial subdividers (Hilbert curves, etc.)

• Multipole expansion for acceleration and higher derivatives

• Pairwise interactions between tree nodes ( evaluations!)

Page 39: Efficient solution of the n-body problem

CONCLUSIONS• Tree methods very efficient

• Performance vs. Accuracy tradeoff possible

• Extremely parallelizable

• Accurate, real-time simulations possible on commodity hardware

Page 40: Efficient solution of the n-body problem

ACKNOWLEDGEMENTS• Dr. Xiang Fu for advisement and helpful discussions

• Dr. Gerda Kamberova for helpful comments on the paper

• Lukasz Bator for many discussions on algorithmic efficiency

Page 41: Efficient solution of the n-body problem

THANK YOU FOR COMING!• Any questions?