CS378: Concurrency: Honors

Lab #6: Barnes-Hut

The goal of this assignment is to use MPI to solve Barnes-Hut.

In this assignment, you will solve an N-body problem using the Barnes-Hut algorithm. You will be forced to deal with an irregular data structure, ie, something other than an array, and you will have to deal with dynamic changing data as the bodies move during the simulation. We encourage you to think carefully about your data structure, because your choice will be central to your solution. You may work with a partner if you wish.

Background

The particular N-body problem that you will solve will be an astrophysical simulation that models the continuous interaction of each body with every other body. In this case the interactions are caused by the gravitational force that each body exerts on every other body, where each body could represent a star, a planet, or a galaxy. As your simulation proceeds, the forces will cause the bodies to move, so this is a dynamic computation that requires an irregular data structure.

Algorithm

There are several algorithms for solving the N-Body problem. The simplest solution directly computes the n*n interactions that exist between every pair of bodies. The complexity of this approach is O(n*n), where n is the number of bodies in the system. You will instead use a superior solution, the Barnes-Hut method, which takes O(n log n) time; this solution computes direct interactions for pairs of bodies that are sufficiently close; for the effects of far away bodies, the algorithm approximates a group of bodies by a single body whose center of mass is the same as the center of mass of the group of bodies. The following papers describe the algorithm in more detail and describe various optimizations.

Algorithm Structure

The algorithm consists of two phases. The first phase constructs a tree that represents a spatial partitioning of the bodies in the system. Each interior node in the tree represents the center of mass of the bodies in the subtree rooted at that node. The second phase computes the force computations for each body in the system by using the MAC (multipole acceptance criteria), which determines whether the bodies in a subtree are sufficiently far away that their net force on a given body can be approximated by the center of mass of the bodies in a subtree. The velocity and position of the body is then calculated via a Leapfrog-Verlet integrator. Since we are approximating the effect of group of bodies by their center of mass, this algorithm takes O(n log n) steps.

The TA will be posting a snippet of C code that performs the actual Leapfrog-Verlet integrator. Alternatively, you can refer to the CUDA example (SDK/examples/nbody), which has code that contains this calculation.

Framework

You should use MPI for this assignment. For better performance, you can use a hybrid of MPI and Pthreads to better utilize the individual Lonestar nodes.

Inputs/Outputs

Your program should accept the following four command line parameters, with types indicated in parentheses:
  1. number of iterations (double)
  2. timestep (double)
  3. input filename (char *)
  4. output filename (char *)

Both the input and output files will have the following format:

You may assume that all initial velocities are 0 in the input file.

Some sample inputs may be found here:

Deliverables

This assignment is due at 11:59pm on the due date. Use canvas to submit your solution, which should include the following:

More detailed instructions will be made available later on our Piazza page.

This assignment is derived from on by Karthik Murthy for Calvin Lin's CS380P course. Thanks very much to both of them!

Please report how much time you spent on the lab.