Homework Assignment #6 [50 points + 10 points extra credit]


Overview

In this assignment we enhance the ics432imgapp application so that a job can use multiple threads to speed up image processing.

In this assignment you have to use GitHub Issues as follows:

How/What to turn in


Question #1 [50 pts]: Multi-threading image processing jobs

We wish to increase performance by overlapping I/O and computation. Create and address the following GitHub issue:

Issue Title: Multi-threaded jobs

Issue Label: enhancement

Issue Description: Add a checkbox to the Main window next to a label that says “Multithreading”. Make it so that if the checkbox is checked when job window is being opened, then that job will use three thread:

There are four requirements (the last one being a non-requirement) for your implementation:

Note: When the Job window displays read, write, processing, and total times once the job completes, the total time should be smaller than the sum of the other three times.

Hint: It’s likely a good idea to define some “work unit” class, which is the thing that gets passed between the producers and the consumers and encodes all necessary information about the work to do for one image. Warning: if your work unit class contains “big” things (e.g., Image, BufferedImage), make sure you set them to null whenever you no longer need them so as to free up memory! In the next question we deal with RAM footprint, so you might as well save on memory right now.

Todo: In your README file, explain where in your code the producer-consumer scheme is implemented.

Todo: Run each filter on the the set of 25 jpg sea urchin images on Laulima, with and without the “Multithreading” checkbox being checked. Do these runs on a quiescent machine. In your README file report on the acceleration factor achieved by multi-threading for running each job (e.g., is a non-multithreaded run takes 10s and a multithreaded run takes 8s, the acceleration factor was 1.25x). Discuss the result, explaining why you think the results are what they are.

Warning: Runs a few “warm-up jobs” in the app before doing your timings.


Question #2 [10 pts - EXTRA CREDIT]: Controlling Memory Footprint

One drawback of our approach is that the reader thread will keep reading images, and thus the memory footprint of the application could grow prohibitively.

Create and address the following GitHub issue:

Issue Title: Controlling the Memory Footprint

Issue Description: Add a Slider to the Main window that makes it possible to select an integer between 2 and 40, with a step size of 2, with some informative label like “#images in RAM”. If the slider’s value is X, then any subsequently created job will enforce that at most X images can be in RAM that have been read in by the reader thread and that are awaiting processing, and at most X images that have been processed by the processor thread and are awaiting being written back to disk. Make the slider long enough that it shows all 20 discrete possible values.

Note: You have to call several of the Slider methods to make sure it does discrete integer steps (e.g., setBlockIncrement, setMajorTickUnit).

Todo: To make sure that your implementation works, let’s use this set of 40 jpg large sea slug images on Laulima. The project’s pom.xml file specifies the amount of heap space that is allocated to the JVM when running the application (the line “<option>-Xmx4G</option>”). Do the following: