Hajara-Yasmin Isa: CS 261 Machine Organization Lab 11 (20 Points)
Hajara-Yasmin Isa: CS 261 Machine Organization Lab 11 (20 Points)
Name: ____________________________
670821591
UIN: ___________
Note:
1. Do not change the pdf form, just fill in the blanks (eg. do not print and scan the
file).
2. Make sure that your pdf is not empty in Gradescope after submission. If it is empty,
print your pdf as a pdf. If you still have any problems, let us know by Friday.
3. Do not forget to submit your VoiceThread video, not just upload it, you need to
click submit. If you are unsure about how to, go through the following tutorial on
submitting VoiceThread videos.
https://docs.google.com/document/d/1HXVSdd1uKORZOP5RGwuVzOd3ws20
nAE-ew9mglz_nvU/edit?usp=sharing
4. Students are expected to submit the lab by Friday, the deadline is Saturday.
For this lab we will be recording the time for the given C code, and optimize the given
code using code motion, Memory references and loop unrolling and record the time
taken after optimization.
To record the time spent running the program use the time command:
gcc lab11.c
time ./a.out
The result are 3 runtimes, we will be using the run time specified by ‘user’ to record the
times.
1. Record the times and fill the table below as you finish each part of the lab (3 points).
// added this local variable as an accumulator that will be used in the third
// for loop instead of accessing result[i][j] everytime.
// This helps with memory accessing instead we can just request for a specific
// element in result such as result[i][j] one time at the end after total has compiled the
// the needed calculation
long total;
// added this local variable so that the get_dim function does not have to copmute
// the necessary calculation over and over again each time the for loops need to
// to evaluate the comparision and determine the termination point for the loop.
// this calers out total everytime so that we have an accurate reading when
// computing the total
total = 0;
for ( k = 0 ; k < length ; k++ ){
total += myMat1[i][k] * myMat2[k][j];
}
// this assignment was added so that the accumulation total contains can be
// in result[i][j]
result[i][j] = total;
}
}
}
3. Modify the labw11 function further by applying loop unrolling as mentioned in class.
Play around with how many times you unroll or how many accumulators you use to see
how much you can further improve the speed of your code. Show your well-commented
code below for labw11 function, highlighting the changes you’ve made, then compile it
and record your user time above (q1) (10 points)
// The changes made in the previous problem are also applied here for the same reasons.
long total;
// I added this to hold the new length I will be iterating over in the main for loop
long limit = ((length / 5) * 5);
// this line of code is used to reduce the amount of time the for loop
// is executed. This helps with the number of times we have to increment and
// compare
}
}
}