CS735/CS835
Programming Assignment 1
(due Sun Sept 29)


This program concerns the multithreaded implementation of a two-stage pipeline. The first stage of the pipeline consists of a single thread generating integer values. The second stage consists of multiple threads checking the integer values to see if they are prime.

This assignment entails running programs, writing programs, and writing a laboratory report in which you analyze and discuss the programs and their performance. The report and the programming will be worth equal amounts in the grading. Programs should be run on lava.cs.unh.edu.

Your first task is to investigate two initial implementations of the pipeline provided in ~cs735/public/prog1. This directory contains a serial implementation (test.java) and a multithreaded implementation (testp.java). Using a sequence of at least 10,000 integers, compare the serial program to the multithreaded program. Run and time the multithreaded program using 1, 2, 3, 4 and 8 threads. Compute speed-up values and analyze the results. Discuss possible explanations for the differences in performance that you see.

The multithreaded program outputs some statistics concerning how many times waiting threads wake up and then immediately wait again. Be sure to consider these statistics in your discussion.

Next you should implement a Mutex class and a Condition Variable class. The Mutex class should include methods for locking and unlocking the Mutex. The Mutex class should be implemented using a FIFO queue for the threads waiting to obtain the Mutex. The Condition Variable class should have a constructor that takes the associated Mutex as a parameter. The Condition Variable class should include methods for waiting and signalling. A thread that calls the methods for waiting or signalling should have locked the Condition Variable's associated Mutex. The Condition Variable class should be implemented using a FIFO queue for the threads waiting on the Condition Variable. Signalling should be implemented using "signal and continue" semantics.

Use the Mutex and Condition Variable classes to re-implement the Cubby Hole buffer used by the multithreaded implementation of the prime-checking pipeline. Use different condition variables for the different reasons why threads need to wait on the buffer. Be careful and try to minimize the amount of synchronization occurring during execution. Run and time this new implementation of the pipeline using 1, 2, 3, 4 and 8 threads. Compute speed-up values and analyze the results. Discuss possible explanations for differences in how this program performs compared to the initial implementation.

Now consider your implementation of the signalling method in the Condition Variable class. What did you do with a thread that was awakened by a signal? Did you put it on the end of the FIFO queue of the associated Mutex? What if you put the awakened thread on the front of the queue instead? Implement the alternative to what you have previously done, re-run the multithreaded pipeline and discuss the performance of the two techniques.

What if you implemented "signal and wait" semantics instead of "signal and continue"? Try it, re-run the multithreaded pipeline, and discuss the performance of the two alternatives.

Extend the Cubby Hole buffer to contain a sequence of storage locations rather than just a single location. Experiment with the initial multithreaded benchmark to see if you can determine what the optimum buffer length is. Is the best buffer length dependent on the number of threads you use?

Finally, implement the extended buffer using the Mutex and Condition Variable class. Study and discuss again the performance of the different possible implementations.

Points will be awarded for this assignment in the following way:

  1. Analysis of the initial implementation: 20 points.
  2. Implementation of the pipeline using condition variables and the comparative analysis:
    1. "signal and continue": 40 points
    2. "signal and continue" with alternative queueing strategy: 10 points
    3. "signal and wait": 10 points
  3. Implementation and comparative analysis of using an extended buffer: 20 points.
Tasks must be completed in the above order.

You should submit your report and all your source code to me via e-mail. Please archive the source code using some standard tool that I can process under Linux. Your e-mail message should include information about how I can process your code archive. Your report should be either just "flat" Ascii or Postscript or PDF. (Please do not send me a Microsoft Word document!)

Do ten runs for each data point to try to avoid anomalies. Try to do your timings at "off hours" when lava is not heavily in use. (This may require that you not do your work at the last minute!) For your report you should summarize the ten runs. Be sure to explain how you summarized the data and include all the raw data as an appendix to your report or in another file in your submission.

To receive full credit for the assignment, you must submit prior to 8am on Monday September 30. Late submissions will be accepted at the penalty of 5 points per day up to one week late.

Remember: as always you are expected to do your own work on this assignment.

Also: you should adequately document and structure your programs.

And: take care with the writing of your report. Use complete sentences, proper punctuation, etc. Use a spell checker. Most importantly, allocate some time for writing your report. Review and revise as necessary. Your writing will be graded for both clarity and mechanics. Finally, don't forget to include the required analysis in your report.


Last modified on September 10, 2002.

Comments and questions should be directed to pjh@cs.unh.edu