the N-body problem

Our third example of data partitioning and divide-and-conquer strategies to create parallel programs falls in the area of particle dynamics, the so-called N-body problem. Given N masses, their initial positions and velocities, the problem is to compute their motion induced by the gravitational forces. Following Newton's laws, we saw that solving this problem corresponds to solving an initial value problem, defined by a second order differential equation, given in vector format by
      2                      (         )
     d p          N          ( p  - p  )
        i        ---         (  i    j )
     ------ = -  >    G * m  -----------   for i = 1,2,..,N
         2       ---       j (         )3
      d t        j=1         ( p  - p  )
                 j/=i        (  i    j )
where the "p" is the position vector of the body, and G is the gravitational constant. A very basic numerical simulation of the motion of the bodies in C can be done (in principle) by the program nbody.c .

An analysis of the cost of this very basic simulation shows a cost of O(n^2) operations per time step. We estimated that for a galaxy of 10^11 stars, the calculation of one time step (at the optimistic rate of 1 billion flops) would take almost a million years.

Fortunately, the bodies (or particles) often occur in clusters and a natural idea is to partition the bodies into clusters, distributed among the processors. Each processor runs a simulation for the cluster of bodies, using the center of mass as the location for each other cluster of bodies, being simulated by other processors. The partitioning uses a Quadtree (for planar) or Octtree (for 3D) data structure. For each time step, the manager node will partition the data using a recursive splitting algorithm which creates the Quadtree. We ended with a technical lemma, stating that the depth of the tree is logarithmic in the data size, so the partitioning algorithm runs in O(N log(N)).