Starting from:
$35

$29

Lab 4: Saavedra-Barrera benchmark Solution




In this lab, you will run the Saavedra-Barrera (SB) benchmark to understand the CPU memory hierarchy. As usual, you may work in teams of two.




Part 0: Getting the scaffolding code




The tarball containing the code for this lab is available at this URL: https://github.com/EECS-UCI/ lab4.git. To get it, use the same git-clone procedure from previous labs.




If it worked, you’ll have a new directory called lab4.







Part 1: Saavedra-Barrera benchmark




Last week in class, we looked at the Saavedra-Barrera (SB) benchmark. It works by first creating an array of length n, and then stepping through the array with stride s, reading an element at each step. It repeats this process many times and reports the average time to read 1 element.




Lets compile and run this benchmark, sb.cc:







 
Compile




g++ -O3 -o sb sb.cc




 
Request an interactive node qrsh -q test -pe openmp 64




...




 
Once logged into the interactive node, run the program:




./sb 2048







The benchmark starts with an array of size n = 1024 and runs the Saavedra-Barrera scheme of varying strides up to 1024/2 = 512. It then doubles the array size and repeats this procedure, up to the maximum array size that you specify. (In this example, specifying 2048 on the command-line will cause the benchmark to try n = 1024 and n = 2048.)




Q1. Run the benchmark to collect data for sizes up to 64 MB, i.e., array sizes up to 16777216 (since each element of the array is 4 bytes). You can use any program (e.g., gnuplot, Excel, MATLAB) to draw the plot. Below, we explain how to use gnuplot for this purpose.




To collect the data, please use the following procedure. First, log into an interactive node.




Run the sb program twice as follows:




2










 
First, be sure you are on an interactive node.




 
Then, start with a "warm-up" run on a small array:




./sb 512




 
Now do the real run on 64 MB (i.e., array of length 2ˆ24):




./sb 16777216 | tee run.txt







The first command is a short warm-up run. Doing this first will help you get stable timings for the real run, which is the second command. The second command collects data by sending (piping) anything that the program writes to standard output to a file called run.txt. (Standard output refers to the cout file variable in sb.cc.)




The run.txt file will have output that looks something like:







1024 1 1.30666e-09




1024 2 1.30656e-09




1024 4 1.3064e-09




1024 8 1.30646e-09




1024 16 1.30645e-09




1024 32 1.30657e-09




1024 64 1.30648e-09




1024 128 1.30642e-09




1024 256 1.3063e-09




1024 512 1.30668e-09







2048 1 1.30649e-09




2048 2 1.30643e-09




2048 4 1.30658e-09




2048 8 1.30639e-09




2048 16 1.30654e-09




2048 32 1.30668e-09




2048 64 1.30643e-09




2048 128 1.30661e-09




2048 256 1.30647e-09




2048 512 1.30639e-09




2048 1024 1.30663e-09







4096 1 1.30648e-09




4096 2 1.3066e-09




4096 4 1.30652e-09




4096 8 1.30644e-09




...







The values mean the following:




 
Column 1 is the length of the input array, in 4 byte words. That is, a value of 1024 means an array with 1024 elements x 4 bytes per element = 4096 bytes.




3







 
Column 2 is the stride, again in 4 byte words. A value of 1 means every consecutive word, a value of 2 means every other word.




 
Column 3 is the average time (seconds) per read.




This output is designed to be easy to plot using the gnuplot utility, though you are welcome to use any other plotting utility (such as Excel, MATLAB, or R) and modify the program output accordingly. If you wish to use gnuplot, the following command will run a gnuplot script we have provided and generate an output file called sb.png.







gnuplot < sb.gp







To view the plot, run the following command:







display sb.png







Q2. From your plot, try to deduce the following:




 
How many levels of cache do there appear to be?




 
For each level of cache, what is its capacity (size)? Line size?




Show your plot and answers to the instructor before leaving the class or submit your answers on Canvas by end of today to get credit for this lab.







Good luck and have fun!

More products