NOTE: This assignment, like the other projects in this class, is due at the beginning of the class period. This means that if you are even a minute late, you lose 20%. If you are worried about potentially being late, turn in your homework ahead of time. Do this by submitting them electronically then giving the hard copy to me or the TA during office hours or by sliding it under my office door within twenty-four hours after the time it is due. Do not send assignments to me through email or leave them in my departmental mail box.
As discussed in class, I/O devices are generally handled on an interrupt basis. That is, rather than having our code (or the OS) waiting for a device to become ready or repeatedly checking to see if it is ready (polling), we prefer to have devices tell us when they are ready.
This assignment will investigate the differences in performance that we can expect to see when these different methods of device handling are used. To do this, you will act as the slow device while the computer does some calculations.
First, write a routine to calculate numbers in the Fibonacci sequence, starting from 0 and 1.
Second, write a program that alternately calculates the next number in
this sequence (using the routine you have just written) and reads keyboard
input. Call the source code for this program
proj1v1. In this program, the user will be
prompted to hit <return> (<enter>). When the user hits
<return>, the program will loop back to calculate the next Fibonacci
number. It will continue running until the user has hit <return> 100
times. This program should time how long this takes, including CPU time
used in user space, CPU time used in system space, and "wall time" (how
much time has passed in the world). The program should report how many
Fibonacci numbers it was able to compute during this time.
Third, modify the program that you have just written so that, instead of
waiting for the user to hit <return>, it should keep calculating
numbers until interrupted by the user entering "Ctrl-C." (The user should
be instructed to enter this instead of hitting <return>.) Call the
source code for this program
proj1v2.c and the executable
proj1v2. As in the previous version of the program, this
version should keep running until the user has made 100 entries (only this
time it will be 100 Ctrl-C's, rather than 100 <return>'s.) Also as
in the previous version, this version should time how long this takes,
including CPU time used in user space, CPU time used in system space, and
"wall time" (how much time has passed in the world) and should report how
many Fibonacci numbers it was able to compute during this time.
Fourth, combine the previous two versions of the program into a single
program that will run waiting for returns when the user starts it up with a
"-w" flag on the command line and will run using interrupts instead when
the user starts it up with a "-i" flag on the command line. If the user
puts anything else on the command line (including combining the two flags
in any way), the program should display a help message to instruct the user
how to run the program, then exit returning an error code. Call the
source code for this program
proj1v3.c and the executable
Fifth, make predictions to answer the following questions. For each prediction, give a reason for the prediction you made. For each prediction, assume that the user types as accurately and quickly when running each version.
Sixth, run your programs, collect the data they produce, and compare these empirical results to the predictions you made. If there are any differences between your predictions and your results, give reasons why you think things turned out the way they did.
You won't be graded on how many predictions you got right. You will be graded on whether your reasons were sound, either at the prediction stage (for correct predictions) or the comparison stage (for incorrect predictions).
All of your input and output in this assignment should use C Standard I/O function calls, not POSIX system calls.
Unfortunately, many of you will not have had any experience doing empirical experimentation. People tend to forget that computer science is an empirical science, as well as a mathematical discipline and an engineering field. For this reason I have provided you with some guidelines for how to test for statistical significance.
You will turn in both a hard copy and an electronic copy of your assignment. Please follow the instructions on how to send electronic copies. Do not send them to my email address.
Both the hard copy and the electronic copy will contain a write-up (see
predictions and results, above) and all source code you used in collecting
your results. The electronic copy will also contain the three executable
versions of your code. The electronic copy of your write-up should not be
in a proprietary format (such as MS Word); it should be either in plain
ASCII text or in a portable format (such as Postscript or PDF). Your
source code for each version should be in a single file called
proj1vi.c and your executable code should be called
i is 1 through 3
for the three versions.
Your source code should be well structured and well commented. It should conform to good coding standards (e.g., no memory leaks).
Besides the statistics and explanations mentioned above, your write-up will include 1/2 to 1 page (roughly 80 characters per line, 50 lines per page) explaining the data structures and algorithms used in your code. This page limitation does not include figures used in your explanation, which are encouraged and may take up any amount of space. (This explanation does not remove the requirement that your code be well commented.)
You may write your program from scratch or may start from programs for which the source code is freely available on the web or through other sources (such as friends or student organizations). If you do not start from scratch, you must give a complete and accurate accounting of where all of your code came from and indicate which parts are original or changed, and which you got from which other source. Failure to give credit where credit is due is academic fraud and will be dealt with accordingly.
As noted in the syllabus, you are required to work on this programming assignment in a group of at least two people. It is your responsibility to find other group members and work with them. The group should turn in only one (1) hard copy and one (1) electronic copy of the assignment. Both the electronic and hard copies should contain the names and student ID numbers of all group members. If your group composition changes during the course of working on this assignment (for example, a group of five splits into a group of two and a separate group of three), this must be clearly indicated in your write-up, including the names and student ID numbers of everyone involved.
Each group member is required to contribute equally to each project, as far as is possible. You must thoroughly document which group members were involved in each part of the project. For example, if you have three functions in your program and one function was written by group member one, the second was written by group member two, and the third was written jointly and equally by group members three and four, both your write-up and the comments in your code must clearly indicate this division of labor.
Some useful commands and system calls for you to consider using in this assignment (besides the ones covered in class) are:
sigactionin detail later in the course. For now, you may use this code fragment/outline to help you incorporate catching the signal generated by Ctrl-C into your code.