diff --git a/exercises/exerciseA/README.md b/exercises/exerciseA/README.md index dbeb721..52c3c2f 100644 --- a/exercises/exerciseA/README.md +++ b/exercises/exerciseA/README.md @@ -30,7 +30,8 @@ In `plot.py`, we have given code that will load all of the timing data in `timin **TASK**: Add code to plot of the execution duration vs. the number of threads -Open a PR with your plotting code and post your plots in the conversation, don't upload binaries to the Git remote! +**TASK**: Open a Pull Request with your plotting code and post your plots in the +conversation. Don't upload binaries to the Git remote! **OPTIONAL TASK**: Add code to calculate and plot the speed-up time compared to single-threaded execution. Include your code and plot in the PR. diff --git a/exercises/exerciseC/README.md b/exercises/exerciseC/README.md new file mode 100644 index 0000000..c5ad503 --- /dev/null +++ b/exercises/exerciseC/README.md @@ -0,0 +1,38 @@ +# Exercise C: blending processes and threads + +Objective: investigate how the number of processes and threads impacts the +speed-up time of a computation. + +## First + +For each of the 19 images in the folder `images/`, the `process_images.py`: +(1) decomposes the image using a singular-value decomposition (SVD), (2) removes the +largest singular value and (3) returns the reconstructed image. The script also measures +the time for the computation and saves the result in `timings/`. + +You can change the number of processes and threads on a set of images by calling the function +as follows: +```python process_images.py 3 2 images/*``` +The code above will use 3 processes and 2 threads to analyse everything in the folder `images/`. + +**TASKS**: + 0. Familiarize yourself with the code in `process_images.py`. Where is the number of + threads set in the code? Why is it set there? Where is the number of processes set + in the code? + 1. Hypothesize what would be a good number of processes and threads for this exercise. + 2. Try a couple combinations of processes and threads, look at the saved timings, and see if + the results match your expectations. + +## Second + +This folder also includes a bash script called `run_with_all_configurations.sh`. + +**TASKS**: + 0. Open the bash script. What does it do? + 1. Execute the bash script in the terminal: + `bash run_with_all_configurations.sh` + Observe what's printed to screen. Does it match your expectations? + 2. Open `plot.py` and see what it does. Run the script and view the results. Do they + match your expectations? + 3. Add the image as a comment to the Pull Request you opened in Exercise A (or make a + new Pull Request if you need one). diff --git a/exercises/exerciseC/process_images.py b/exercises/exerciseC/process_images.py index 0aa76dd..db0774a 100644 --- a/exercises/exerciseC/process_images.py +++ b/exercises/exerciseC/process_images.py @@ -45,7 +45,7 @@ if __name__ == '__main__': # we need to set the variable before numpy is imported! os.environ['OMP_NUM_THREADS'] = str(n_threads) - # We delay the import of numpy because we want to set OMP_NUM_THREADS. + # We delay the import of numpy because we have to set OMP_NUM_THREADS before import. # We delay the import of PIL in case it uses numpy internally. import numpy as np from PIL import Image