CPSC 521 assignment 1
This program performs an n-body physics simulation with one body per process. The code is parallelized with MPI, using only basic MPI functions like
This assignment has several macros that can be changed at the top of the source code to alter its behaviour. Some of them are:
SCALAR_MPI_TYPEcan be set to
MPI_DOUBLE(the default), or to
MPI_FLOATto use single-precision floating point.
RING_COMMswitches between ring communication and broadcast-style communication. You can also control which algorithm is used more finely with
VISUALIZE_OUTPUTgenerates periodic reports of the positions of all particles, in a format that can be interpreted by the nbody visualization program (see assignment 4).
DEBUG_OUTPUTis as it sounds, it enables lots of debugging output per iteration.
There is also
SERIALIZE_VELOCITIES, if you want the program to have larger messages being sent.
It turns out that the ring communication is much more efficient than broadcast communication: in a typical case of 8 processes and 8 bodies and 1000000 rounds, ring takes 4.799 and broadcast takes 9.081 seconds. Clearly, using a ring instead of my initial first-intuition scheme is a better idea.
Using floats is actually slower than doubles (doubles take 4.799 and floats take 5.262 seconds in the same case as above) on the given hardware setup. This is only based on one test case and results may vary for different scenarios.
Finally: both this assignment and the next calculate velocities and positions alternately, staggering them so that the new values can be used (i.e. backward Euler, not forward). This results in a system that should conserve energy better.