Week 5: File Input/Output (I/O) & structures
Topics:
Opening, reading, writing, closing files. File pointers. Structures (structs) in C.
Reading:
K&R sections 6.1-6.4, 7.5
Notes:
Source:
EX08: creating a new variable type in C with substructure (struct) [ main.c, vector.c, vector.h, Makefile ]
EX09: opening a file called data, reading entries from the file, closing the file [ fileio.c, data ]
EX10: reading strings with fgets, input and output functions in the standard IO library [ file_input.c, file_output.c, data ]
Screen captures:
09/19/11 CAAM420F11_V11.mov [ building a variable type to represent a vector with typedef and struct ]
09/21/11 CAAM420F11_V12.mov [ discussion of HW04. Simple file input. ]
09/23/11 CAAM420F11_V13.mov [ Simple file input and output in C . Resolving Subversion conflicts. ]
Notes:
Subversion conflict resolution: need blog notes on resolving Subversion commit conflicts here
Week 8: Introduction to LaTeX
Notes:
CAAM420F11_Week_07.pdf [ typesetting documents with LaTeX. ]
Source:
EX16: [ simple LaTeX document example] main.tex, main.bib, Makefile, helloworld.c, graph.pdf
Screen captures:
10/10/11 CAAM420F11_V18.mov [ Introduction to LaTeX by example ]
10/12/11 CAAM420F11_V19.mov [ More details on using Kile: tables, listings ]
To install LaTeX: sudo apt-get install texlive
To install Kile: sudo apt-get install kile
To install Octave: sudo apt-get install octave
Links: kile, Listings package.
Week 7: Introduction to Fortran (simple tutorial here)
Topics:
Comparison of C & Fortran syntax and function calling contention. Calling Fortran subroutines from C.
Dense Linear Algebra Libraries:
BLAS & LAPACK ( see: BLAS quick reference and LAPACK quick reference )
Notes:
CAAM420F11_Week_07.pdf [ Fortran introduction. ]
Source:
EX13: [ simple fortran example ] intro_fortran.f, as well as [ mixing together C and F77 ] Makefile, main.c, fortran.f
EX14: [ matrix-matrix multiplication using BLAS ] matrices_blas.c
EX15: [ solving AX=B using LAPCK ] Makefile, matrices_lapack.c
Screen captures:
10/03/11 CAAM420F11_V15.mov [ comparison of C and Fortran/F77. Calling F77 subroutines from C. ]
10/05/11 CAAM420F11_V16.mov [ Basic Linear Algebra Subprograms: BLAS. Example calling dgemm from C. ]
10/07/11 CAAM420F11_V17.mov [ Linear Algebra PACKage. Example calling dgesv from C. ]
Note:
To install lapack and blas libraries in ubuntu: sudo apt-get install liblapack-dev
Week 6: Multi-dimensional arrays
Topics:
Two-dimensional call stack arrays. Row-major storage convention. Representing multi-dimensional arrays with heap memory.
Notes:
CAAM420F11_Week_06.pdf [ the Gnu Make system, Linking libraries, typedef, the Gnu Scientific Library. ]
Source:
EX11: [ accessing the command line arguments, simple matrix representations: call stack v. heap ] argggggs.c, matrices.c
EX12: [ different modalities for representing a 2D matrix in C ] matrices_redux.c
Screen captures:
09/26/11 [ technical difficulties meant that the lecture not recorded. See V14 for a recap on storing 2D arrays in C ]
09/28/11 CAAM420F11_V14.mov [ 5 matrix representations: stack, heap, “multi-d” heap, struct, access functions ]
09/30/11 [ No video. In class board presentation only ]
Week 4: Working with arrays in C
Topics:
Pointers and arrays, dynamic/heap vs. automatic/stack memory allocation,
malloc, calloc, realloc and free, typical usual dynamic memory bugs and how to avoid them.
Reading:
K&R sections 5.1-5.4, 5.10-5.11, 7.2, 7.4
Notes:
Source:
EX06: automatic.c, dynamic.c (automatic & dynamic array allocation, pointers, in-bounds and out-of-bounds memory access)
EX07: sieve.c (sieve of Eratosthenes algorithm for finding prime numbers (wiki) example using dynamic memory allocation,
circumventing scope restrictions by passing a pointer to a variable as a function argument)
Screen captures:
09/12/11 CAAM420F11_V09.mov [ Memory spaces in C: call stack and heap memory pools. allocating arrays in C ]
09/14/11 CAAM420F11_V10.mov [ Prime numbers, dynamic memory allocation, finding memory errors & Valgrind ]
Week 3: Functions in C
Topics:
Functions, pass-by-value vs. pass-by-reference, return values, function scope, prototypes, pointers
Reading:
K&R sections 1.7, 1.8, 4.1-2, 5.1.
Notes:
Source code:
EX04: (function prototyping, make) Makefile, main.c, foo.c, foo.h
EX05: Makefile (supply your own hw02.c). To use with debugging turned on: make DEBUG=1
Screen captures:
09/07/11 CAAM420F11_V07.mov [ function scope, forward declaration, function prototypes, make ]
09/09/11 CAAM420F11_V08.mov [ debugging: compiling -g, more Makefiles, the gnu debugger gdb ]
Background:
The TIOBE index indicates the popularity of programming languages. Note the rank of C and C++.(click here for link)
Week 2: Numerical Computation in C
Topics:
Floats, doubles, constants, statements, functions, equality test vs. assignment,
evaluation of expressions, for and while loops, conditional branches, arrays,
multi-dimensional arrays.
Reading:
K&R 1.3, 1.4, 2.1-8, 3.5
Notes:
Source code:
EX01 helloworld.c and arithmetic.c
EX02 variables.c and functions.c
EX03 forloop.c and my_cos.c
Screen captures:
08/29/11 CAAM420F11_V04.mov [ starting C ]
08/31/11 CAAM420F11_V05.mov [ variables and functions in C ]
09/02/11 CAAM420F11_V06.mov [ cosine function C code example ].
Week 1: Linux/Ubuntu/Virtualbox/Subversion
Topics:
Unix/linux. Source code management with Subversion.Intro to C
(variables, type, assignment, main program, header files)
Reading:
K&R 1.1, 1.2
Notes:
Screen captures:
CAAM420F11_V01.mov [ Using VirtualBox ]
CAAM420F11_V02.mov [ Simple Linux commands ]
Week 5: File Input/Output (I/O) & structures
Week 4: Working with arrays in C
Week 8: Introduction to LaTeX
Class meets 11am to 11:50
Monday, Wednesday, Friday
Location: Humanities 117
Instructor: Tim Warburton
Course overview: CAAM420F11_Overview.pdf
Grading policy: CAAM420F11_Policies.pdf
The C Programming Language (2nd Edition) by Brian W. Kernighan and Dennis M. Ritchie (Prentice Hall) ISBN-10: 0131103628.
LaTex Companion, The (2nd Edition), (Tools and Techniques for Computer Type Setting)
by Frank Mittelbach, Michel Goossens, Johannes Braams, David Carlisle, and Chris Rowley (Addison Wesley Professional) ISBN-10: 0201362996.
The C++ Programming Language (Special 3rd Edition) by Bjarne Stroustrup
(Addison-Wesley Professional) ISBN-10: 0201700735
HW1: CAAM420F11HW01.pdf
HW2: CAAM420F11HW02.pdf
HW3:CAAM420F11HW03_corrected.pdf
HW4: CAAM420F11HW04.pdf
HW5: CAAM420F11HW05.pdf
HW6: CAAM420F11HW06.pdf
New HW7: CAAM420F11HW07.pdf
Skeleton code: HW07.web.tar.gz
Week 7: Introduction to Fortran (simple tutorial here)
Week 6: Multi-dimensional arrays
Week 3: Functions in C
Week 2: Numerical Computation in C
Week 1: Linux/Ubuntu/Virtualbox/Subversion
Reading List
CAAM 420 Time & Place
CAAM 420 Fall 2011 Course Information
Homework Fall 2011
Click to download coding flowchart
Week 8: Introduction to LaTeX
Notes:
CAAM420F11_Week_09.pdf [ basics of C++ ]
Source:
EX17: [ simple C++ examples: helloworld and passing by reference] helloworld.cpp and references.cpp
EX18: [ calling C from C++, dynamic memory allocation, class] mangling.cpp, cfunction.c, dynamic.c, vector.cpp
EX19: [ default, regular, and copy constructors, const functions, destructors,
operator overloading, member functions, public/private, breaking the private access restriction ] vector.cpp
Screen captures:
10/17/11 CAAM420F11_V20.mov [ C++: compiling, name mangling, pass by reference, function overloading ]
1019/11 CAAM420F11_V21.mov [ C++: turning off name mangling, linking BLAS/LAPACK, // commenting, new/delete for allocating and
freeing dynamic memory, classes: constructors, member variables & functions, operator overloading ]
10/21/11 CAAM420F11_V22.mov [ C++: see comments for EX19. Overview of HW05. ]
Links:
• Tutorials and reference material at cplusplus.com (tutorial).
• Notes on passing by reference, function overloading, and prototyping
• Eric Brasseur’s neat notes on C++ programming for C programmers (link).
Week 9: Introduction to C++ (Part I)
Week 8: Introduction to LaTeX
Notes:
CAAM420F11_Week_09.pdf [ basics of C++ ]
Source:
EX20: [ revisiting simple C++ classes ] vector.cpp
EX22: [ C++ inheritance, pure virtual functions, virtual functions ] vector.hpp, dvector.hpp, fvector.hpp, main.cpp, Makefile
See EX22/Makefile for a demonstration of how to force .cpp files to recompile because of .hpp header files they depend on changing.
Screen captures:
10/24/11 CAAM420F11_V23.mov [ Aspects of C++: reviewing C++ constructors & member functions. ]
10/26/11 CAAM420F11_V24.mov [ Mostly audio from lecture on class hierarchy, part I. ]
10/28/11 CAAM420F11_V25.mov [ Lecture on class hierarchy, part II. ]
Trouble shooting:
Week 10: Introduction to C++ (Part II)
Week 8: Introduction to LaTeX
Notes:
CAAM420F11_Week_09.pdf [ basics of C++ ]
Source:
EX23: [ Simple matrix class: HW05 solution & C++ strings/file output ] contents of the directories dmatrix.v1 and dmatrix.v2
EX24: [ Templated functions, templated classes, intro templated vector class ] templated_functions.cpp, templated_vector.cpp
Screen captures:
10/31/11 CAAM420F11_V26.mov [ The C++ string class and stream based file IO. Ex: upgrading the simple dmatrix class. ]
11/02/11 CAAM420F11_V27.mov [ Templated functions and templated classes. ]
Links:
C++: string class intro, input/output intro, templates intro.
Week 11: Introduction to C++ (Part III)
Week 8: Introduction to LaTeX
Goal:
Set up a finite element solver as an example application using some simple C++ classes, and existing libraries for sparse matrix algebra. We will start with mesh generation (gmsh), importing a finite element mesh into our own code and move on to setting up a stiffness matrix S and then solve Sx=L for FEM solution x given some load vector (or set of load vectors) L.
Extra C++ language features:
Along the way we will cover sorting an array, and using try/catch/throw for error handling.
Source:
EX25: [ sample geometry file and mesh file generated with gmsh ]
EX26: [ reading mesh file in C++. Input file stream. Exception handling with try-throw-catch. ] mesh.cpp, needs matrix.hpp
EX27: [ least squares approximation of an L2 function FEM hat functions. Introducing stack tracing (gnu only) ] (tarball)
Makefile, main.cpp, fem.hpp, mesh.hpp, matrix.hpp, blaslapack.hpp, trace.hpp, headers.hpp. Code review next lecture.
Screen captures:
11/07/11 CAAM420F11_V28.mov [ Using gmsh to generate finite element meshes, i.e. triangular mesh partitions of a domain ]
11/09/11 CAAM420F11_V29.mov [ Setting up a simple mesh class with exception handling and gmsh .msh input constructor ]
11/11/11 No screen capture: blackboard presentation of least squares approximation of an L2 function.
Notes:
slides19.pdf, lecture19.pdf from CAAM 453/553, 2010 on least squares approximation of a function.
Links:
Week 12: Applied Example (building a finite element solver from scratch)
Week 8: Introduction to LaTeX
Goal:
When the finite element system for L2 approximation is constructed we are left with the challenge of handling large, sparsely populated matrices. This week we are looking at sparse matrix storage in the context of C++.
Extra C++ language features:
Along the way we will incidentally see: function pointers, and a go-between entry class.
Source:
EX28: [ sketching a C++ sparse matrix class ] sparse.hpp
EX29: [ filling out a C++ sparse matrix class ] main.cpp, sparse.hpp, headers.hpp, matrix.hpp, blaslapack.hpp, trace.hpp
Screen captures:
11/14/11 CAAM420F11_V30.mov [ Displaying the function call stack. Building a sparse matrix class. ]
11/16/11 CAAM420F11_V31.mov [ Nested templating of classes. Matrix of matrices. Overloaded type conversion operator.
Communicating between classes: templated active sparse entry class. ]
11/18/11 CAAM420F11_V32.mov [ Overview of HW07. ]
Notes:
Loop current method: (link). Node potential method: (link)
Links: Inkscape vector art program (link) to install under virtualbox/ubuntu: sudo apt-get install inkscape
Week 13: Applied Example (building a simple sparse matrix class for a finite element solver from scratch)
Week 8: Introduction to LaTeX
Goal:
Keep on trucking with building up infrastructure for a finite element solver: building an element-element connectivity list.
Extra C language features:
quicksort
Source:
EX30: [ mesh connectivity ] connect.cpp, mesh.hpp, sparse.hpp, headers.hpp, matrix.hpp, blaslapack.hpp, trace.hpp
Screen captures:
11/21/11 CAAM420F11_V33.mov [ Connecting elements in a finite element mesh. Edited for flubs. We will fix the code. ]
Week 14: Applied Example (find pairs in a list to connect elements in a finite element mesh)