Fall 2000
This homework involves writing a number of C programs that are
used to test how long it takes to perform simple arithmetic
operations. You also need to write a C program that can run the
unix time command on any of the arithmetic programs, so
you can measure how long it takes to run them (and so you get
some experience playing with exec()). All code must be
in C (no shell scripts please)!
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 |
Write 3 similar programs, one that does integer multiplication, one that does floating point addition and one that does floating point multiplication. In all cases, do your best to minimize the code that is not part of the specific arithemtic operations being measured (don't add a lot of other stuff!). I named my programs like this:
iadd.cimult.cfadd.cfmult.cAll four programs should accept a single command line parameter that indicates the number of operations to be done.
Write a program that does the following:
time command on the proper program
Your wrapper program can either exit once the measurement is made
(as will be the case if it calls exec directly) or can
continue to prompt the user for another operation/count (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.
hw1.c, and here is what it
looks like when I run the program:
> ./hw1
Select desired operation:
1 Integer addition
2 Integer multiplication
3 Floating point addition
4 Floating point multiplication
1
Enter number of iterations
100000000
Spawning ./iadd 100000000
2.38 real 2.35 user 0.00 sys
> ./hw1
Select desired operation:
1 Integer addition
2 Integer multiplication
3 Floating point addition
4 Floating point multiplication
3
Enter number of iterations
100000000
Spawning ./fadd 100000000
2.69 real 2.69 user 0.00 sys
>
|
Your submission must include the following:
Source code for all 5 programs
A README file that includes a single line description of the contents of each file, the machine type and compiler used to compile/test your code, instructions on how to run your program and anything else you want to tell us.
A brief writeup that includes the following:
A summary of the results of testing each of the operations (perhaps come up with an estimate of the number of operations per second for each of the 4 operations). A table would be nice!
A paragraph or 2 describing what happens when you change the operands (does it matter what specific additions are done, or do they all take the same time?).
Submission Instructions are here. Please make sure you send submissions to comporg-submit@cs.rpi.edu not to comporg@cs.rpi.edu!!!