hw16: Shakes
- Due before the beginning of class on Wednesday, March 18
Today’s homework asks you to run a small bash script that executes a provided Python program 10 times. You will then modify the script so that the 10 runs all happen concurrently and compare the results.
You will need to submit a Google form answering some specific questions about your experiments.
Downloads
Run git pull in your sd212 directory.
You should see a new folder with two files:
Tasks and questions
For this homework, we are mostly asking you to experiment with the code that you are given and make a couple small modifications to the bash script. You don’t need to write a lot of code; this is more about testing things for yourself and understanding what’s going on.
Complete the tasks below and fill in your answers by completing this Google Form before the deadline: https://forms.gle/xRtufNVe39tEJtvi8
Look at the code in
shakes.py. Maybe try running it on the command line by typing for examplepython3 shakes.py 15.Describe briefly what this program does.
The bash script you downloaded
run-shakes.shjust runs the Python program with ten different numbers. Time the execution by running on the command line:time bash run-shakes.shYou will see three timing numbers reported. The first (“real”) is the actual elapsed “real” time, and the second (“user”) is the amount of CPU time that was used. Answer this question by reporting these two numbers.
Now modify
run-shakes.shso that it runs the Python programs concurrently by backgrounding them. You need to make two changes:Add a
&at the end of each line so that the python3 programs run in the background, like this:python3 shakes.py 16 &Add a new line at the end with the single command
wait
After making these changes, time the execution again:
time bash run-shakes.shand report the real and user time numbers.
Besides the timing, what is different about the output from the “parallel”/backgrounded version compared to the original version?