| CompOrg Fall 2001 |
|   Assignment   |   Stuff you need to know   |   What and How to submit   |   Grading   |   Notes and Hints   |   FAQ |
|
Assignment |
There are two parts to this homework:
Do problem 2.13 from the text. You need to answer the first 2 questions only, and you must show your work (the numeric answer is not enough, you must show how you derived the numeric answers). You only need to answer the first two questions which are (paraphrased):
Develop some C programs that can be used on a Unix machine to compare the time it takes to do some simple arithmetic operations. You need to write a total of three C programs, these are listed below:
Write a program that accepts a single command line argument that
specifies the number of integer addition operations that should be
done. The program should then perform the specified number of
integer addition operations and then exit. No output should be
generated by this program. Here is what it might look like to
compile and run the program (I called mine iadd.c),
including using the unix time command to see how
long it takes:
> gcc -o iadd iadd.c > ./iadd ERROR: ./iadd needs a count > ./iadd 10000 > time ./iadd 10000 real 0m0.011s user 0m1.003s sys 0m0.004s > time ./iadd 100000000 real 0m2.738s user 0m1.661s sys 0m0.009s |
This program is just like the integer addition program, except that the operation done is multiplication and the operands should be floating point numbers.
Write a program that does the following:
time command on the proper program
Your wrapper program can should run the appropriate program (using
exec),
and then prompt for the next operation and count. Your wrapper program
must not exit after the first operation, it must support multiple
operations (to accomplish
this you will need to have the wrapper program fork, and then have the
child do the exec - the parent can just go back and ask the user for
the next test, you should have the parent call wait()
before prompting for the next operation).
hw2.c, and here is what it
looks like when I run the program:
> ./hw2
Select desired operation:
1 Integer addition
2 FP multiplication
Q Quit
1
Enter number of iterations
100000000
Spawning ./iadd 100000000
2.38 real 2.35 user 0.00 sys
Select desired operation:
1 Integer addition
2 FP multiplication
Q Quit
2
Enter number of iterations
100000000
Spawning ./imult 100000000
6.87 real 6.71 user 0.00 sys
Select desired operation:
1 Integer addition
2 FP multiplication
Q Quit
Q
>
|
|
Things you will need to know |
Understand how to use the performance equations described in Chapter 2, including those that depend on mixes of classes of instructions.
Understand fork() and exec() system
calls.
Understand how to use the Unix time command.
Understand how to test your program to make sure that the desired operations are actually happening (that the compiler did not reduce your code and eliminate the actual operations we want to measure).
|
Submitting |
You should submit all the source code for the programming part of the homework - this should involve three individual C programs (submit each as a separate file).
You should submit a description of your answers for the written part of the homework (problem 2.13) as either a text file, html file, Microsoft Word document or Adobe PDF.
You should submit a file named "README" that lists the other files submitted and a brief description of the contents of these files (this is so we know which program is which), and you should mention the specifiec machine type and operating system used to develop/test your programs. IMPORTANT: You need to include the command line used to compile your programs!
Projects must be submitted via email to comporg-submit@cs.rpi.edu. The subject line of the submission message should contain a single number indicating the project number (2 for HW2). You must include your files as attachments, feel free to send a zip-file or a tar file.
Don't send compiled code!You can expect a return email indicating receipt of your project submission immediately. This receipt will include a list of all the files that were successfully extracted by the submission script - please look over the receipt carefully to make sure your submission worked.
Multiple Submissions: You can resubmit up to 10 times for each project, we will always grade the last submission received unless you tell us otherwise.
|
Grading |
The written part of the homework counts for 50% of the grade, and the programs count for 50% of the grade. Partial credit is possible, so submit whatever code you have, along with a brief description of what the problems are (what the code does/doesn't do correctly)
|
Notes and Hints |
You need to be a little bit careful when writing the programs that do the addition or multiplication operations. Compilers will attempt to optomize your code, so if you have something like this:
for (i=0;i<cnt;i++) {
a=1+2;
}
and you assume that the addition operation a=1+2 will
be executed cnt times you may have trouble. It is
possible that the compiler will recognize that nothing new is being
computed (the value of a never changes after the first
time through the loop), and simply eliminate the loop...
You should expect that your program will involve some CPU time that is not attributable to the iterated operation (for example the loop control may actually be significant compared to what happens inside the loop). You can easily measure this by running the program with various kinds of operations inside the loop and making measurements. We expect that the code you submit does actually provide a time value that can be used to compare the execution time of integer addition and floating point multiplication operations. (you must make sure that the compiler has not eliminated your operations!)
You may want to check out the sample code,
there are a number of examples of using fork() and/or
exec().