ASTR415/688C Spring 2005 Problem Set #1

Due February 22, 2005

This problem set is designed to familiarize you with computer programming, shell scripting, and simple visualization. You will also learn about benchmarking. Questions marked with a leading are optional for ASTR415 students but mandatory for ASTR688C students.

HINT: If you plan to use C for this assignment, and you're new to the language or need a refresher, be sure to read the Intro to C document first. It provides information on, for example, using internal clocks to measure code performance. You should also read the other introductory documents on Unix (especially scripting) and visualization.

1. Write a program to time the CPU expense of various mathematical operations, as listed in the table below. Do each operation times, where is supplied by the user. Your program should output the final value obtained after cumulative iterations of each operation, and the CPU time required to complete them. For the moment, do not make use of compiler optimizations.

 Operand Type Starting Value Operation integer add 1 integer subtract 1 integer 1 multiply by 1 integer 1 divide by 1 double-precision 0.0 add 1.0 double-precision 0.0 subtract 1.0 double-precision 1.0 multiply by 1.000001 double-precision 1.0 divide by 1.000001 double-precision 1.1 take square root (sqrt(x)) double-precision 1.1 raise to the 0.5 power (pow(x,0.5))

1. Write a shell script to construct a table of execution times for double-precision addition and multiplication as a function of for = , , , , , , and .

2. Do the square-root and raise-to-the-power functions give much different execution times? Comment.

3. Plot the data in the table, execution time as a function of , using any plotting package you like. The axes should use a logarithmic scale. Estimate the number of floating-point additions and multiplications your code carried out on average per second.

4. How does your code performance compare to standard benchmarks for your machine, if available? (Check the LINPACK performance chart.1)

5. Redo questions 1a and 1c after recompiling your code with optimizations turned on (e.g., try the -O2'' compiler flag) and plot the results. Is there a difference? Also try a different compiler if possible, with and without optimizations (e.g., if you used gcc, try icc next.2) Comment on the results and suggest why differences exist.

2. How long did it take you to finish this problem set?

Remember, your solutions to this problem set should be e-mailed to me as a single attachment (astr415@astro.umd.edu). See the syllabus for more information. Be sure to make your code and script bomb proof'' as much as possible.