CS472/CM472/CS672 - Computing

Course Newsgroup:

The course newsgroup is uw.cs.cs472. Please post questions there, especially those whose answers will be of general interest to the class. For instructions on how to read and post to a newsgroup, check out the FAQ maintained by MFCF.


The IST group maintains a nice set of online references for Matlab including a tutorial.

Notes on the C Programming Language

For many of you the C Programming Language will be new. Some of you are coming from Applied Math and will be using Unix and C for the first time; you will need to set aside some extra time to familiarize yourself with the new tools. In addition to these notes, don't forget the general resources provided by MFCF and also the MFCF Consultants who are there to help you with general problems.

Using C is not difficult, but neither is using it incorrectly or using it badly. If you know Perl, C++ or Java then you already know most of the basic syntax, since C is a parent of all of these languages. It is much more primitive, however. It was selected for the course because it is relatively simple, and is frequently used in real life for scientific programming.

Scientific software is extra tricky in that it rarely fails with a simple error. Scientific code is very good at producing answers which look right, but which are quite wrong. Careful programming style (keep it simple) and careful debugging are the key to saving yourself time.

Learning C

Some resources to get you started with the C Programming Language:

Using purify

In C it is very easy to write programs that exceed array bounds or which leak memory. Always check your programs using purify. Always correct all of the problems which purify reports.

For more information on purify, see the manual pages by typing

     man purify
     man purerun
and read the IBM/Rational Purify Plus information page. In particular, you might want to read

Purify is available in the undergraduate environment under the directory


There is an option built into the makefile we supply for you that compiles your programs with purify. Purify will tell you clearly where there are memory problems in your program and (particularly) where there are none.

Programs which leak memory or run over array bounds are incorrect and will be marked as such.

If you are coding at home then valgrind is a good, open source and free alternative to purify.

The make Command

To build the programs you will submit for your assignments we have provided a makefile. The make command searches for a file of this name in the current directory, then uses the instructions in that file to build an executable program. Normally, you will never have to compile a program using the C compiler; you should only ever need make and the makefile we provide.

To write the code for this course we strongly recommend you follow this general pattern:

  1. Create a directory for each assignment and put the supplied materials in that directory. The materials will be supplied in a zip file and you will unpack with with a command
        unzip assignX.zip
    (changing the assignX.zip file name, of course).
  2. Read the README file, which tells you what files to edit. Do your work directly on those files.
  3. To compile the program for debugging use the command
        make debug
    which will create an executable file programDebug in the working directory. To run this program the command is
        purerun ./programDebug
    or without purify (after there are no more errors from purify):
  4. After you have corrected all of your bugs (including all of the bugs reported by purify) then you should produce an optimized executable for testing timing and speed. Do this with the command
        make opt
    which produces the program programOpt. This version is free of all of the extra code and overhead produced for debugging. You run it with

Simple Graphical Debugging

The debugging program gdb or the graphical xxgdb is available on the MFCF undergrad environment. If you are working from home you may wish to try the powerful debugger DDD.

Unfortunately, the graphical debugger xxgdb is not really state of the art, but it should be adequate for our purposes.

Some Debugging Tips