Homework 1
cs599 Parallel Programming and Algorithms
5 points
Due: Tuesday, Jan. 27, 2015 at the beginning of class

1. (0.5 points) Write a C program that will print out any size square using dashes ('-'), pipes ('|'), and pluses ('+'). Use fgets and sscanf to read in the height in number of lines. The size must be greater than three.

2. (0.5 points) Write C a program that will print out the maximum value in a given double array. Assume the array is provided as text input (using stdin) and use a function to find the maximum. You must pass the array into this function as a parameter. You may assume a maximum of 20 elements in the array.

3. (1 point) Read about each of the following supercomputing systems and determine each system's ranking on the Top 500 list (top500.org), and describe what makes each of these systems unique. Use at least two sentences per item below.

a. TACC Stampede
b. PSC Blacklight
c. SDSC Gordon
d. LSU SuperMIC
e. RIKEN K Computer

4. (1 point) Parallelize the following code using OpenMP parallel and reduction directives. Ensure that your program prints the output and tracks and prints the time expended by the program.

const int NUM_ITER = 100000000;
int i;
double sum = 0.0, x = 0.0;
double st = 1.0/((double) NUM_ITER);
for(i = 0; i < NUM_ITER; i++)
{
  x = (i + 0.5)*st;
  sum += 4.0/(x*x+1);
}

5. (1 point) What does the program above compute? Plot the CPU time expended by the serial version of the program and by running the program with 2, 4, and 8 threads. Note that the x axis of your plot should be threads used, and the y-axis of your plot should be time expended in seconds.

6. (0.5 points) Follow the instructions on worksheet 1 to set up an account on xsede.org. Send your username to the instructor in an email. Once your XSEDE account is activated, activate your TACC account.

7. (0.5 points) Assume that you are given a double variable called bankAccount in which several threads will deposit random amounts of funds. Write a C program that uses OpenMP to deposit random amounts of money (between 10 and 20 dollars) into the bankAccount. You may assume that the number of threads will be the same as OMP_NUM_THREADS.