CS 336: Project #5

Project 5: Fish production line

On NSCC, create a proj05 directory.

In this project, you will be simulating a production line. What will be coming down the production line? Fish! Of course, it must be fish. Let's think of it though as fish that are going to be cooked, so the fish themselves don't move. They are passed from worker to worker in a production line. Imagine that each worker needs to do something to the fish so that it can be packaged into a somewhat palatable frozen entree. The workers are lined up sequentially -- a fish first goes to worker 1, who then hands it off to worker 2, etc. Between each pair of workers is a holding area for the fish. Each holding area can hold just one fish. So if worker 2 is looking for work, it needs to wait until there is a fish in the holding area between worker 1 and worker 2. When there is, it removes it, does something to it (simulate actual fish-prep work by calling sleep for 0, 1, or 2 seconds), then puts it into the buffer between worker 2 and worker 3. Worker 2 can put the fish into this next buffer only when its becomes empty.

Your goal is to write multiple versions of the program and to compare the speed of execution (let's measure that in the average time it takes for a fish to be entirely processed).

  1. Write the first version of the program. Let's call it fish_production_single.c. It should pass one fish at a time. The buffers between the workers can hold one fish. Use condition variables to keep track of full and empty buffers, just as one would in a producer-consumer problem.
  2. Write the second version of the program. Let's call it fish_production_batch.c. It should pass multiple fish at a time. The buffers between the workers can hold one to BATCH_SIZE fish. Implement it so the BATCH_SIZE can be adjusted by you the programmer or you the user. The rule here is that the entire batch must be finished before the batch can be put into a buffer. And the entire batch is removed from the buffer.
  3. Write the third version of the program. Let's call it fish_production_multiple.c. In this case, the buffers can hold multiple fish, but the workers put in one fish and remove one fish at a time.
  4. Compare the timing for these programs for a range of total-number-of-fish-to-produce. Adjust the batch size and buffer size in the second and third versions. I am not going to prescribe for you the ranges. Choose ranges that provide a good description for the program under light and heavy load. Varying the buffer size and batch size will be more interesting than varying the total number of fish, so I suggest you focus on them.


Writeup and Handin

To hand in your project, you will gather all of the necessary files into a proj05 directory:

  1. Create a file named README.txt or README.docx (or some other format) for your project write-up. Like last week, I want you to collect timing information from all of your runs and then analyze the results. The analysis is a significant part of the project, so don't leave it until the last minute, when you are too tired to think clearly. Here's the data I want you to collect: the number of seconds it takes to run each "version" of the program (i.e. with each set of parameters your consider). You should record this 5 times for each program version. Drop the min and max values from these 5 and then report the mean of the middle 3. What conclusions can you draw? Please include any figures that make your data easier to understand. Figures are good. Figures are great. We like figures.
  2. You should hand in all code necessary to run your solutions. Place all necessary .h, .c, and Makefile files in the proj05 directory. Stephanie will probably want to compile and run the code. It should be possible to do so without looking for any more files.

Compress it and email it to Stephanie.