Skip to content

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.

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, ...).

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 &, and xterm -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.