Software Engineering for Scientific Computing
COMPSCI 194-73 (CCN 27274) / COMPSCI 294-73 (CCN 27241)
Instructor:
Phil Colella
643 Soda Hall / 50A-1121 LBNL
colella at cs.berkeley.edu
Class Location: 306 Soda Hall (HP Auditorium)
Class Time: TuTh 11:00-12:30
Office Hours: TuTh 1:30-3:00, or by appointment.
Teaching Assistants
Brian Van Straalen
643 Soda Hall
Office Hours: Friday 10:30-12:00
cs294.73.brian at gmail.com
Kevin Wang
350 Hearst Mining
Office Hours: Mon & Wed 3:30-5:00
kevinwang at berkeley.edu
Fall 2011
1 Introduction
This course is intended for non-CS graduate students
(CS294) or advanced undergraduates (CS194)
interested in high performance computing and scientific simulation. The
focus will be on skills and tools that cross most disciplines, and how
they are applied towards larger software development goals. The course
will be taught in the context of several dominant algorithmic motifs
found in scientific computing: dense and sparse linear algebra,
structured and unstructured grid methods, N-body problems, FFT. The
course will be taught using C++, although no prior experience with the
language will be assumed. Specific topics will include:
- Working in a typical Unix environment, Makefiles, compilers, revision control systems, debuggers, profilers.
- Fundamentals
of C++. Functions, pointers, references; scoping; classes,
encapsulation, inheritance; templates; memory management.
- Fundamentals
of data structures and algorithms (arrays, graphs, lists; recursion,
sorting...) as they arise in scientific computing.
- Asymptotic analysis of algorithmic complexity.
- Correctness debugging and performance debugging.
- Engineering larger systems: factoring, reuse, dependencies, composition, use of external libraries.
2 Course Structure
2.1 Format
2 lectures a week, 80 min. per lecture.
2.2 Prerequisites and Restrictions
To enroll in CS 294, a first-year graduate course in the
sciences or engineering covering an area in which simulation is
commonly used and at least one of the motifs listed above arises (can
be taken concurrently). To enroll in CS 194, the students will have had
to have taken an advanced undergraduate course in an an area in which
simulation is commonly used and at least one of the motifs listed above
arises. Some experience with computing applied to science (e.g E77
level); or the consent of the instructor.
2.3 Grading
There will be 6 homework assignments, adding up to 45% of
the final grade. Class participation and attendance is 10%. The final
project is worth 45% of the grade. There might also be an optional
bonus homework for 10%.
Homework is to be submitted through the revision control
system. Outside class work should comprise about 5 hours a week during
the early course time, and up to 10 hours a week in the final month of
class project time. It is hoped that the class project forms a suitable
foundation for the students develop complicated thesis software
modeling efforts. For CS 194, the students will be provided with a
framework for implementing common
final project. For CS 294, the students will be required to develop a
final project coming from their own discipline, in consultation with
the instructor; organization into teams of 2-3 students will be
permitted.
3 Reading List and Resources
- Code Complete: A Practical Handbook of Software Construction
http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670
- O’Reilly Subversion
- O’Reilly GNU Make
- Stroustrup C++ Language Reference
- Myers Effective C++
3a Getting your work environment ready
A laptop is recommended, as that will let you bring your problems
and your computer to the professor and TA office hours and get direct
help on your own machine. The next best is your own
workstation. Third place is access to a UNIX style account.
Neither the professor nor the TAs know anything about Microsoft
Windows. We're sorry. For what it is worth, nobody that does
scientific computing professionally that we are aware of is using a
Windows operating system for their work. Also, all supercomputers
and large scale computing facilities run UNIX style operating
systems. So, consider this your head start. For the
Windows users in the class we STRONGLY recommend you put a Linux
distribtuion on your machine. There are three main choices facing
you at this time
Set your computer up to be a dual boot machine. In day
past this was a horrifyingly tedious process, but Ubuntu has made it
quite natural. Just go to www.ubuntu.com/download/ubuntu/windows-installer.
This does mean you have to reboot your computer when switching to your
linux world and your Windows world. This is the most reliable
operation mode however, as you boot into a real honest-to-gosh linux OS.
Set yourself up to run Ubuntu as an application inside Windows with www.andlinux.org.
This is called a Beta, but so far testing has been acceptable for most
simple operations. The downside, this will not work if you are
using a 64-bit version of Windows. It is all built using 32-bit binaries.
Cygwin www.cygwin.com/install.html.
Ever maligned and cursed, but this old dinosaur from the DOS days is
still maintained and works. When running setup.exe make sure you
select all the development tools
The Minimal GNU for Windows http://www.mingw.org/
gives you make, g++, svn, gdb, and most of the tools you need.
Like andliux, the emacs editor can be a bit wiggy, since the X server
is not fully debugged, but the tools you need for the course are all
there.
Mac
users will need to have a version of XCode installed on their
machine. It is not a part of the default installation but it is
on your distributed disk/thumb drive as an additional installation
(XCode 3.x). You will need to put /Developer/usr/bin in your
terminal path (remember, under Mac OS X is a real BSD unix operating
system, most of the shell commands we give you work fine in the bash
shell you access with your Terminal application). DO NOT USE THE
XCODE ON THE APPLE APP STORE. It is a horror of breakage at this
time.
You will need a sane and powerful editor on your system.
You can pick an easy editor, then grow weary of using your mouse to do
everything, or a powerful editor, and feel like a bumbling fool for the
first month. Some options
First choice, Emacs. We use it, lots of programmers
use it. You'll look like a pro when you master it, which nobody
ever really does. On linux it is already there, for macs visit http://www.macupdate.com/app/mac/19269/carbon-emacs. Linux users might like to use xemacs instead www.xemacs.org.
It has menus and buttons for when you forget a command. The Mac
carbon emacs already has all these nice buttons and menus for you.
So, you have never used UNIX ?
VisIt download page
4 Course outline
Square brackets indicate lecture numbers.
- Course Introduction [1]
- Before we get started
- Using Unix (Unix, Linux, OSX, cygwin, mingw)
- get your tools installed: g++, gmake, svn, gdb, prof.
- Course outline, grading, projects, schedule.
- The Seven Dwarves [2]
- Compiled vs Interpreted Languages [3]
- C/C++/Fortran, compiler, objects, libraries, executables.
- Python/Java, byte code, virtual machine, JIT, matlab.
- Perl/shell
- Operating system basics
- compiler flag basics: -O, -g
- Development Management [4]
- Revision Control Systems (svn)
- Configure
- Make: dependencies, rules, targets.
- C++ key language features.[5,6]
- functions, pointers, pass-by-reference, pass-by-value, return value.
- equivalent features in Fortran, Python, Java, C.
- special topic: multi-language projects.
- Scoping.
- Object-oriented programming.
- Classes, encapsulation, inheritance.
- Templates.
- Memory Management. The Heap and The Stack. part 1.
- command-line options, argv, argc
- Software Engineering Concepts [7,8]
- Coding Standards (including the Coding Standard for this course)
- Data basics
- Naming conventions.
- Minimize scope.
- Globals
- Class basics
- Encapsulation
- Rational default behavior.
- get+set=public (except when it isn’t).
- Good formatting accompanies good structure.
- The various purposes of comments.
- Structured Grid [9]
- class MDArray
- Fortran has it, Matlab has it, you want it.
- data+methods.
- providing an algebra. from primitive type to Class.
- stencil iterators.
- special topic: function templates vs. member functions and performance.
- I/O, pretty-printing, visualization.
- Motif Example: Forward-Euler diffusion problem.
- Skill development: Debugging [10]
- compile errors, warnings.
- printf debugging
- gdb
- gdb with GUI (ddd, emacs+gdb, Nemiver, Xcode)
- list, up, where, print, breakpoint, step, next.
- calling functions (name-mangling, gdb+VisIt).
- the silent bug: memory leaks.
- Floating-Point.
- Debugging Assignment. 1 program, 15 bugs, 15 marks.
- Sparse Linear Algebra[11]
- class Vector, class SparseMatrix
- public interface, private interface, friends (or not)
- export to matlab.
- Homework Motif Example: Conjugate Gradient.
- Asymptotic analysis and algorithmic complexity. [12,13]
- Introduction to Profiling and simple Optimization [14]
- instrumenting profilers, sampling profilers.
- call tree, inclusive, exclusive.
- hot-spots and bottlenecks.
- Instruction Level Parallelism, Cache.
- loop re-ordering, loop fusion, inlining.
- Optimized Conjugate Gradient Homework.
- Dense Linear Algebra and Fast Fourier Transform[15,16]
- Better to buy than to build. trade-offs.
- The harder optimizations: vector instructions, data locality, auto-tuners.
- ...and why you don’t want to do these yourself if you can help it
- BLAS, LAPACK, FFTW, external libraries, more Makefiles.
- extern C, Fortran, Python, Java options.
- SparseMatrix x Vector revisited.
- FFTW example program: signal processing.
- Unstructured Grids and Graph [17,18]
- class Tree, Graph, PlanarGraph
- ”is-a” ”has-a”, protected.
- Template Pattern and C++ Templates.
- graph traversal. DFS, BFS.
- Recursion: coding, The Stack and The Heap part 2, unwinding.
- Planar Graph Separator Theorem.
- Spanning Trees.
- Homework Example: Linear Elasticity Finite Element program
- Managing project complexity and team development.[19]
- Revision Control Systems revisited.
- Headers, prototypes.
- doxygen
- unit testing.
- test targets.
- making libraries.
- triangular dependencies, insulation.
- Bigger Example, Crank-Nicholson Diffusion Equation [20]
- Derive formula, stability.
- MDArray, Vector, SparseMatrix, CG
- Profiling again.
- CN Homework.
- Final Project Discussion and Timeline. [20]
- Project scope and suggestions.
- final projects submitted to class svn repo
- configure, Makefiles, sources, input files
- N-Body Problem [21]
- class List
- double vs single linked list, insertion, traversal, deletion.
- container classes.
- being fast at what you do the most.
- Motif example + homework Graph, Graph+List, PIC
- Multi-level Schemes[22,23]
- Many motifs have optimal implementations expressed in multilevel form.
- Graph partitioning
- Fast Multipole Method
- Cache-oblivious dense algebra
- Multigrid
- Recursion again.
- The Multigrid Algorithm
- Homework: class MDArray for Muligrid
- Dictionaries. Keeping track of the explosion of parameters [24]
- Hashing
- Hash code
- Hash table
- other applications (compression, digital signatures).
- map
- Dictionary Homework.
- Special Topic: A Tour Through Language and Compilation [25]
- Assembly Code and machine instructions.
- Compilation, AST.
- The Illusion of Sequential Execution
- Special Topic: And the world is all parallel. [26]
- MPI, OpenMP, PThreads.
- UPC, CUDA, Vectors.
- Parallel IO
- Where to go for more
5. Links to Lectures
Lecture 1 - preliminaries, a short introduction to computer architecture, the motifs. (revised 10/1/11)
Lecture 2 - Our first C++ programs: Hello World, and others.
Lecture 3 - Pointers, references,and user-defined types.
Lecture 4 - C++ Classes, Development Tools
Lecture 5: Development Tools Continued
Lecture 6: Structured Grids
Lecture 7: Building, Testing and Debugging
Lecture 8 Supplemental
Lecture 9: Unstructured Grid / Finite Elements
Lecture 9 Templates
Lecture 10: FEM Assembly and SparseMatrix
Lecture 11: Fast Fourier Transform & Homework 1 outbrief
Lecture 12: Fourier Transforms and Third-Party Libraries.
Lecture 13: Streams, Inheritance, Debugging Again
Lecture 14: Dense Linear Algebra (guest lecture by J. Demmel)
Lecture 15: Particle Methods; Homework #3
Lecture 16: std::list, std::map, Project Info
Lecture 17: Particle Methods; Homework #4; Homework #3
Lecture 18: Performance Debugging
Lecture 20: Final Project Material
Lecture 21: Advanced Make, Configure, Autoconf, Automake. Anatomy of a Program
Lecture 23: Visualization Using VisIt
Lecture 25: Mixed Language Programming