CompOrg Fall 2001

Homework #2 - Performance and Benchmarking

Due Date: Thursday, Sept 20th by 11:59PM

Assignment

There are two parts to this homework:

  1. 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):

    • How much faster is M1 than M2 when using C1?
    • How much faster is M2 than M1 when using C2?

  2. 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:

    Integer Addition Program

    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
    

    Floating-point Multiplication Program

    This program is just like the integer addition program, except that the operation done is multiplication and the operands should be floating point numbers.

    Wrapper program

    Write a program that does the following:

    • Allows the user to select one of the 2 operations:
      • Integer addition
      • FP multiplication
    • Allows the user to type in the number of operations desired.
    • runs the Unix 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).

    I named my wrapper program 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
    >
    
  3. Things you will need to know

    Submitting

    What you need to submit

    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!

    How to submit

    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