Using C/C++/C
C/C++/C# Books
Most of my programming is in C, so most of the material on this page will be directly relevant to C programming. C++ moved C into Object oriented programming, while C# allows C to function in the Garbage Collation environment (an automated memory management system; for more follow this link). This link takes you to a useful discussion of the differences between the programming languages
- Schildt, H., C: The Complete Reference. This is my preferred comprehensive reference book. It is not a training document, but still provides an easy way for me to look up commands and functions that I use, but not often enough to remember them completely.
Getting Started with C/C++/C
The C programming language is installed on all RCAC cluster systems. The most common development compiler is the Gnu Project C compiler (gcc), but the module system on the cluster computers will allow you to replace it with different versions when your specific needs require a specific compiler.
-
Training options for the original C programming language (used for the VIC model and many others)
-
C Tutorial from W-3 Schools is a complete language lesson.
-
C Tutorial from Tutorials Point, another reliable source.
-
C Programming Language Tutorial from Greeks for Geeks, yet another reliable source for training materials.
-
-
Training options for C++, the object oriented version of the C programming language
-
C++ Tutorial from W-3 Schools.
-
C++ Tutorial from Geeks for Geeks.
-
Debugging
Basic Debuggers
These debugging tools are generally available on Linux systems, and are designed to be language agnosits, but this page and the resources provided will focus on its use debugging C languages. However, the tools should function similarly for other programming languages (e.g., Fortran, Java, ...).
-
The GNU Project Debugger (gdb) - for command line debugging.
Note
You will need to load the full or correct (if you have changed the default compiler) gdb module on the RCAC cluster systems usinf
module load gdb
.-
How to debug c programs using gdb in 6 simple steps. A quick start guide to using gdb to debug your code.
-
The gdb step by step introduction. A more interactive debugging tutorial.
-
Data Display Debugger (ddd) is a GUI interface to gdb.
Note
This program requires a lot of bandwidth, so can be slow even on local Purdue computers, and nearly impossible over home internet connections. As with gdb, it will have to be loaded before being used.
-
General dubugging help
- The Art of Debugging with GDB, DDD, and Eclipse is available for purchase and an an ebook from the Purdue libraries.
Memory debugging
Total user control of memory management is one of the strengths of the C programming languages, however, with control comes the prospects of having to find memory leaks. The gdb debugger paired with the valgrind memory mnagement and threading debugger is the best tool to help you find those pesky memory problems.
-
Valgrind is a tool for finding memory leaks and other memory problems. Basic information for getting started with the valgrind tool can be found by following this link.
Note
Valgrind is available to use on RCAC cluster computers, however, you will need to run
module load valgrind
to load valgrind into your current shell. Make sure that you load valgrind AFTER you load your preferred compiler in order to load the correct version for your preferred compiler.Hint
The vgdb module is a within valgrind that allows valgrind to run simultaneously with gdb so that it will check memory, while you use gdb to set break and watch points, and interact with the code as valgrind finds problems.
Here are some suggestions for working with valgrind on Linux computing resources based on Dr. Cherkauer's experience:
-
To work with this on the RCAC cluster systems, you will need to start an interactive session with x forwarding (e.g.,
qsub -X -I -q standby -l walltime=4:00:00
). Then start two xterms (e.g.,xterm -sb -title window1 &
, andxterm -sb -title window2 &
). -
Then you can follow the instructions for running vgdb by following this link, while this link provides a little more context but is not as complete.
-
To debug a program that requires command line arguments, use them when starting valgrind\'s vgdb and they will be available when you link gdb to vgdb.
-
-
The Valgrind Quick Start Guide is maintained by the valgrind organization.
-
Using Valgrind to Find Memory Leaks and Invalid Memory Use is a useful tutorial for first time users.
Debugging Parallel Processes
The previous tools focus on debugging a single C language code running in series on a single CPU. Given the increasing use and need for parallelized code, there is also a growing need for tools to help debug these complex processes. Fortunately RCAC provide access to the TotalView debugger, which has been designed specifically to deal with debugging most parallel programming models/APIs.
Note
TotalView is available to use on RCAC cluster computers, however, you will need to
run module load totalview
to load totalview into your current shell. Make sure that
you load totalview AFTER you load your preferred compiler in order to load the
correct version for your preferred compiler.
Note
To use TotalView for debugging parallel code on RCAC cluster systems, you will first need
to request access to compute note resources required to run the program in parallel as an
interactive session (sinteractive
), then load the compiler and totalview modules. You
cannot debug a parallel session from the front-end computers, since those do not have access
or the ability to run jobs in parallel on the compute nodes.
-
Lawrence Livermore National Lab maintains a set of three tutorials for TotalView, accessible from their tutorials page.
-
All three parts are useful for new users, but Part 3 on its own is a good refresher if you have used the tool before.