Lab: Parallelized Image Restoration

CSC 213 - Operating Systems and Parallel Algorithms - Weinman



Summary:
You will devise a synchronization strategy for a parallel multi-threaded implementation of an algorithm for cleaning up noisy images.
Assigned:
Tuesday 30 October
Due:
This assignment will be due in three parts
Part A
10:30 PM Friday 2 November
Part B
10:30 PM Friday 9 November
Part C
10:30 PM Monday 12 November
Objectives:
 
Reading:
A Brief Introduction to Iterated Conditional Modes (ICM), which provides background on the algorithm we'll be using.

Preliminaries

Exercises

Part A: Algorithm design

Now you will devise a parallel implementation of the ICM algorithm. With sufficient processing power, each iteration could take constant time, rather than time proportional to the size of the image.
Assume that your algorithm will run as threads on a shared memory multiprocessor (e.g., a MathLAN workstation). There are several ways to partition the problem into a parallel implementation (the example in pinvert.c, which is likely similar to your prior parMtxMultiply, is one partitioning), but your parallel implementation must meet requirements: Write a design paper that addresses the following: Hint: One nice solution to this problem extends the barrier pattern so that it is reusable. In other words, the barrier can be used within a loop. The key is to create, in addition to a turnstile that ensures all threads rendezvous at the beginning of a section of code, another turnstile syncs them at the end of the looped code. This prevents one thread from lapping another by getting ahead one iteration. While the first in turnstile is only unlocked once all threads have arrived (by incrementing and checking a variable), the second out turnstile is only unlocked when all threads have completed (by decrementing and checking the same variable.)

Part B: Implementation

Implement the multi-threaded version (using POSIX threads) of your parallel algorithm by copying icm.c to picm.c and modifying the existing functions and introducing any necessary new functions. Like icm, your program picm should accept the filenames of an input and an output image. It should also take as a command-line parameter the number of threads to create.
Preserve the wall clock timer to measure time for the algorithm. (You'll find that I/O dominates the overall time.)
The parallel and single-thread versions should produce the same results on all images. To assert this, the command diff(1) will tell you whether two files are the same. If you want to create an image that shows you the difference between two images (rather than just whether there is a difference), you can use this handy program:
compare image1.pbm image1.pbm differences.png
which will overlay the differences in red pixels in output images differences.png on top of a matted version of image1.pbm. For a simple binary output, use differences.pbm, which will be black where pixels differ and white where they're the same.

Part C: Performance analysis and evaluation

Revise your design from part A to include any changes you made and any other feedback.
Integrate your revised design within a paper that also analyzes the performance of your algorithm, including the following elements:
Setup
Describe the experimental setup, including the number of cores on your machine, image size, algorithm parameters, etc.
Experiment
Do the experiment, reporting the number of ICM update iterations required for convergence. Use the bash time command to measure the times used by both the single- and multi-threaded programs (with 1, 2, 3, 4, 8, 16, and 512 threads) for one of the noisy palisade images. For each run, record the user and system times from time and the wall clock time from main.
Report
Use a spreadsheet (or another tool of your choice) to create plots of the number of threads versus the three times, as well as the speedup and efficiency (using only the wall clock time).
Summarize
Give a brief, objective overall picture of the performance:
Infer
Draw conclusions. Write a paragraph explaining the results. Why do you see the patterns in your results?
Recommend
Make recommendations. What lessons have you learned about parallel programming on a multiprocessor?

What to turn in

Part A
A single PDF of your algorithm design.
Part B
 
Part C
A single PDF of your (revised) design from Part A and your analysis.

Acknowledgments

Janet Davis contributed notable improvements to the text. The public domain Palisade image is by the Pearson Scott Foresman company. The Dilbert image is Copyright 2008 Scott Adams, Inc.
Copyright © 2012 Jerod Weinman.
ccbyncsa.png
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.