| Date | Description |
| 13-Oct-13 | Original posting |
Your assignment is to parallelize the rapid many body particle simulation, discussed in class, with C++11 threads. As in the previous assignment your starting point is serial code. We’ve also provided a multithreaded executable that will enable you to assess performance.
Conduct experiments on the Bang cluster to assess scalability. If Bang becomes too heavily loaded, do your development on Ieng6. In the spirit of friendly competition, post your performance results to the A2 Moodle forum.
The assignment includes a brief report, and the requirements for your report are described at the end of this writeup.
We've provided you with starter code that implements the serial algorithm. We've also provided a reference binary that supports multithreading so you can assess performance. This code has been installed in an SVN repository that resides on Bang.
To use the svn repository, take the following 3 steps.
svn co --username your_AD svn://ccom-bang-login.ucsd.edu/SVN/A2/ProvidedWhen working on Bang, you'll check out the code differently:
svn co --username your_AD svn://localhost/SVN/A2/Provided
svn co svn://ccom-bang-login.ucsd.edu/SVN/A2/Turnin/YOUR_GROUP_ID Turnin
cp Provided/* Turnin cd ./Turnin svn add * svn commit -m "import the provided code"
So you don't have inconsistent copies different machines, make sure that you keep your repository up to date before you log out or interrupt a login session. You can check on the status of your files with the svn status command. Commit any file with the 'M' tag (modified but not committed).
To build your code, use the provided Makefile, which sets up the appropriate flags for the compiler via an included "arch" file located in $(PUB)/Arch/arch.gnu-4.7_c++11. $PUB should be defined in ~/.bash_profile on ieng6 as
export PUB= /home/linux/ieng6/cs160f/public
and on Bang as
export PUB=/share/class/public/cse160-fa13
The Makefile produces a target called nbody. Do not change the name of this target and do not add additional source files to the Makefile, as we'll be grading your assignment with our own Makefile.
The algorithm used in this assignment takes advantage of knowledge about the underlying physical problem. In particular, because the force induced on a particle drops off rapidly with distance (see plot below), we may safely ignore forces that drop below a certain value, the cutoff. The value of the cutoff is 0.01 in our simulations.
We sort the particles, based on their coordinates, into a geographic data structure, a 2d array, called a binning mesh. The binning mesh divides the simulation region into a uniform array of boxes, each box containing all the particles residing in the corresponding region of space.
|
The force between two particles with the same y-coordinate is defined as follows.
| Force(x) = C*(dx) | |
| where | C = (0.01/r2 - 1/ r3) |
| r = max( dx, 10-3)) | |
| dx = distance (in x) between the two particles | |
Each bin of the mesh contains a list of particles situated in the physical region of space covered by the bin. We organize the computation (apply_force) around this mesh and need only look to boxes whose i and j coordinate differs by at most one. While the algorithm is still O(N2) in the worst case, we have reduced the number of computations significantly since we only search in nearest neighbor boxes. We can solve much larger problems than the slower method that must compute distances between all pairs of particles.
The code allows you to specify the shape of the binning mesh via the -x parameter (binning meshes are square so you specify just one number). You’ll vary the -x parameter to optimize the running time, subject to the constraint that the bin size must not drop below the cutoff value of 0.01 units. If you select a value that doesn't meet this constraint, the code will issue a warning and exit. Note that, as you increase the -n parameter, the size of the computational region, as measured in floating point valued spatial units, grows as sqrt(n). This ensures that the density of particles remains constant as n increases. Thus you will need to increase -x in order to optimize the running time, subject to the above constraint.
In this assignment you'll implement BLOCK partitioning in one dimension. Since the iterator that visits each box of the binning mesh enumerates a 1-dimensional iteration space, you'll split the mesh into horizontal strips.
Familiarize yourself with the various modules. The command line parser in cmdLine.cpp explains the options needed to run the code.
The program defines two main classes to store the binning structure. The first classed, called Bins, defines the 2D array. Each element of the array is an object of class Box, containing a vector of particles.
Bins.{cpp,h} defines the Simulate() member function which controls the overall simulation via two other member functions, Bins::move_particles() and Bins::apply_forces, that update the binning structure. In turn, these functions apply identically named member functions (but of class Box) to each bin, i.e. Box::move_particles() and Box::apply_forces.
Your changes will be made to five (5) files:
Bins.cpp Bins.h Box.cpp Box.h nbody.cpp
To ensure that your program is correctly graded, do not rely on any changes you have made to any of the provided source code files, other than those in the above list. We will substitute fresh copies of the remaining files when we grade your assignment, including the Makefile. Please check that this is correct and that we might find later on that they need to change other files Don't change the signature of functions defined in particles.h as provided code makes callbacks to them.
The code has various capabilities, which are controlled via command line flags explained in cmdLine.cpp. For example the following invocation
./nbody -n 16384 -t 1000 -nt 8 -x 40 -p 10 -s 1352723313 -o 16k.out
will run a problem of size 16384 particles for 1000 timesteps on 8 threads. The particles will be organized in a 40 × 40 mesh binning structure. The results will be plotted via gnuplot and output every 10 timesteps. S random number seed is specified via the -s flag. (See below in the discussion of Testing your code.) We also asked to output the positions of the particles to a file called "16.out" You may find the output option handy when debugging your code, in conjunction with summary output mentioned below.
The plotting capability, controlled via the -p flag, uses gnuplot, and may be useful in debugging. It runs on the main thread only and is not multithreaded. The plotter (Plotting.cpp) interfaces with gnuplot, which is free-ware.
Remote visual display can be slow if you are off campus. If a display window does not appear on your screen, then your ssh display settings are not set correctly. If you are connecting to the remote machine from a Linux platform using ssh, use the -X option:
% ssh -X yourlogin@ccom-bang-login.ucsd.edu
If you are connecting from a Windows platform, and are using a 'secure shell client' AND 'exceed' (or xwin32, or cygwin) to log into a remote machine you must ensure that 'X11 tunneling' is set. To do this, you must have installed Cygwin /X with X11.
You be able to improve performance by further tuning the -x parameter for each value of the number of threads. However, it is not necessary to conduct a two parameter study of -x and the number of threads over all the values of -x that you tested on one core.
Take timings with the provided timer code (it uses gettimeofday()) which measures wall clock time. On Bang, use an interactive qlogin node, or a batch queue, to collect timings. Take at least 3 timings for each combination of parameters, and report the minimum timing.
Instructions for submitting jobs via the batch queue are described in
http://cseweb.ucsd.edu/classes/fa13/cse160-a/Bang/runningJobs.html
When you are measuring running times for your performance studies, do not enable plotting (-p) nor output the result to a file using the -o option, as doing so could affect your observations.
Your code will report 2 accuracy measures that you can use to determine if your code is correct. These values reflect information about all the particles in the simulation and hence is a summary error. Compare the two reported values against the single threaded run, obtained with the following command line parameters: ./nbody -x 40 -s 1359856190 -nt 8
(u,v) Max = ( 2.27641850e+00, 2.84668447e+00 ) (u,v) L2 = ( 5.81159812e-01, 5.81967427e-01 )
These values should agree to the full printing precision (9 significant figures) when you vary the number of threads. However, as you grow the -x parameter, you'll note changes in the last 3 digits. Such changes are due to roundoff errors that are a side effect of how the particles are organized in the chaining mesh. We will accept these errors which should never affect the higher order 6 digits. Larger errors indicate an error. Note that, if you run for sufficiently long times (-t option) and/or with more particles, you may note larger errors, even in an otherwise "correct" code. These errors are an artifact of the computation so explore this regime with care.
Since the initial particle distribution is random, each run will use a different particle distribution, making it impossible to test for correctness unless we have a way of generating the same random number sequence at will. As in the previous assignment, use the -s flag to start the random number sequence from a known place. For each combination of input variables such as -t, -n and so on, run 3 times with the same seed and report the minimum time.
We will grade your assignment on bang. Be sure to do your final testing on that machine, to avoid any surprises at turnin time.
We will test your code's correctness and performance. We will test against the public input described here, plus other inputs that will not be made public. Be sure to test against various combinations of the -t, -n and -x command line parameters.
Negative results are also valid and especially valued if you can document them, with the underlying causes, or best guesses if the causes are not clear.
Take care in how you plot your data, only plotting what's necessary to get your points across, and choosing log and linear plots carefully. You must also include any plotted data in tabular form. Tabular data may be included electronically (in your turnin) as a spreadsheet or other document called, e.g. Data.xlsx, Data.txt.
Cite any written works or software as appropriate in the text of the report. Citations should include any software you used that was written by someone else, or that was written by you for purposes other than this class. In such cases you must talk with us prior to get our approval.
In addition to source code files, your electronic turnin must include a Makefile so that we can build and test your code.
Your turnin must also include the following two important documents. These documents are required as the grading process which not complete without them. Empty forms, or forms not properly filled out, will result in a 10% penalty being assessed, in addition to holding up the grading process.
| Don't wait until the last minute to complete the assignment. The batch queue can become full, the machine unresponsive, so try to get results early on rather than all at the end. You also need time to tabulte and plot your data and this can take more time than you think. Be sure you are familiar with svn, and commit code frequently. |
We will use a script to measure your code's performance and test for correctness. We will also look at code since some correctness errors cannot be tested automatically. Except for the code files mentioned above, our tester will use fresh copies of all code files, so any changes you made to those files be lost and therefor will not affect your grade.
Your grade will based on results obtained from your code, and documentation. Documentation includes the report, comments in the code, and svn log entries. The grade for the code will depend on two factors: performance and correctness. The grade for your documentation will be based on clear explanations, and in the case of the report, insight into the results and presentation of experimental data. Remember: the report is brief so you need not go into long explanations. Focus on what's important. When you commit files with svn, be sure to add brief, but descriptive comments, suitable for understanding your development process. If you aren't sure, be sure to ask us.
To get full credit on the programming portio of the assigment your code must
Copyright © 2013 Scott B. Baden [Fri Oct 11 09:59:29 PDT 2013]