Due: Friday, April 10th by 11:59 PM

Getting Started

Download CS365_Assign03.zip. Unzip it on the cluster head node (or your local machine, if you are running Linux).

There are two source files nbody_seq.c and nbody_par.c. These source files are initially the same (except for a comment at the beginning of the file.) You can compile both programs using the command:

make

To run the programs:

./nbody_seq

./nbody_par

If you are going to compile this on your own computer running Linux, you will need to have the XForms development libraries installed. On Ubuntu, Debian, and Mint, run the command

sudo apt-get install libforms-dev

N-Body Simulation

An N-Body Simulation is a simulation of the motion of an arbitrary number of physical bodies influenced by physical forces, such as gravity:

image

The simulation consists of a collection of particles, which are the bodies. At each time step of the simulation, for each particle in the simulation, the forces on that particle are computed. In the case of simulating gravitational attraction, a particle will be attracted to every other particle, with the magnitude and direction of the force depending on the distance between the particles and their relative positions.

Because each particle acts on every other particle, there are O(N2) interactions that must be simulated at each time step.

Your Task

Your task is to modify the nbody_par.c program so that it uses threads to speed up the computation in the nbody_tick function. Use exactly 4 threads. The basic idea is to have each thread update a different range of particles at each time step.

You will need to think carefully about how to parallelize the computation.

Hints

Here is a suggested approach:

Grading

Submitting

Run the command

make submit

Type your username and password when prompted.