CS 336: Homework

Homework Assignment 2 (due Thurs Sept. 18)

The goal of this assignment is to give you practice writing and compiling a sequential C program using a simple text editor and a Terminal command window. The directions are written for a Mac OS X, but only minimal (if any) changes will be needed for Cygwin on Windows or a terminal on a *nix box.

Open a Terminal window and change to your favorite directory (.e.g. your home directory) (hint: cd ~). Create a cs336 directory (hint: mkdir cs336). Change directories to cs336 (hint: cd cs336), and create a hw2 directory. Then, create directories for code and executables (hint: mkdir src for the source code and mkdir bin for the executables). Now you have a directory structure set up so that your code is separated from your executables.

Problem 0: Put hello.c and Makefile into your src directory. Compile hello using the line make hello. Run the program by typing ../bin/hello. If it doesn't print out "Hello, World", then something is terribly wrong. Come see me!

Problem 1: Download prob1.c to your hw2 directory. This is similar to the last example we had in class on Thursday. In particular, it attempts to print out one element past the end of the array. Compile it and run it. Record the output. The last number printed on each line is unreliable because it is pointing to memory that has not been allocated to it. Tell me what output you see and what you think caused it (i.e. Why is the last value of the first line a 5? etc.). WARNING: Even if your conjecture is correct, you cannot count on the same thing happening every time/place you run it!

Problem 2: Create a file prob2.c in your hw2 directory that creates two integer variables, prints them out, swaps their values, and prints them out again. To do this you will need to write a swap routine that takes two pointers to integers. When calling the routine, the address of the integer variables should be sent so that the contents of the variables themselves can be changed, e.g. if a and b are declared to be ints, then the call should be swap(&a,&b). There are numerous solutions to this problem on the web, but you won't learn anything by simply copying them. I want you to write it yourself and experiment with bad implementations. Turn in your code and an explanation of an alternate set of code (i.e. a code snippet) and why that alternate code will not work.

Problem 3: Chapter 2 of the textbook provides a nice explanation of the diverse configurations of parallel computers. Read the section titled "A Look at Six Parallel Computers" (pp. 31-44) and write a few sentences telling me about the computer that most grabbed your attention. Search the web for an example of that computer being used in research or industry and describe it. To get you started, check out the San Diego Supercomputer Center or the list of the top 500 fastest computers.

What to Turn in

Please put all of the homework problems into a single document (txt, doc, docx, pdf). You can turn in either a hard or electronic copy (if it is electronic, just email it to me).



Back to Homework Page