NERSCPowering Scientific Discovery Since 1974

Valgrind

Description

The Valgrind tool suite provides a number of debugging and profiling tools that help you make your programs faster and more correct. The most popular of these tools is called Memcheck which can detect many memory-related errors and memory leaks.

Using Valgrind

Prepare Your Program

Compile your program with -g to include debugging information so that Memcheck's error messages include exact line numbers. Using -O0 is also a good idea, if you can tolerate the slowdown. With -O1 line numbers in error messages can be inaccurate, although generally speaking running Memcheck on code compiled at -O1 works fairly well, and the speed improvement compared to running -O0 is quite significant. Use of -O2 and above is not recommended as Memcheck occasionally reports uninitialised-value errors which don't really exist.

Load Module

 module load valgrind

Running Serial Programs

If you normally run your program like this:

./myprog arg1 arg2

Use this command line:

valgrind --leak-check=yes ./myprog arg1 arg2

Memcheck is the default tool. The --leak-check option turns on the detailed memory leak detector.

Your program will run much slower (eg. 20 to 30 times) than normal, and use a lot more memory. Memcheck will issue messages about memory errors and leaks that it detects.

Running Parallel Programs

In your batch script, simply 1. load the module; 2. add "valgrind" in front of your command. For example, your aprun line will be replaced by the following:

module load valgrind
aprun -n 24 valgrind --leak-check=yes ./myprog arg1 arg2

Link to Outside Documentation

This page is based on the "Valgrind Quick Start Page". For more information about valgrind, please refer to http://valgrind.org/

For questions on using Valgrind at NERSC contact the consultants at consult@nersc.gov.

Availibility

PackagePlatformCategoryVersionModuleInstall DateDate Made Default
Valgrind carver applications/ debugging 3.9.0 valgrind/3.9.0 2014-01-06 2014-01-06
Valgrind edison applications/ debugging 3.9.0 valgrind/3.9.0 2014-01-06 2014-01-13
valgrind genepool applications/ programming 3.7.0 valgrind/3.7.0 2012-09-28 2012-09-28
valgrind genepool applications/ programming 3.9.0 valgrind/3.9.0 2014-05-05
valgrind hopper applications/ debugging 3.6.1 valgrind/3.6.1 2011-03-25 2013-05-03
Valgrind hopper applications/ debugging 3.8.1 valgrind/3.8.1 2013-05-03 2013-05-03
Valgrind hopper applications/ debugging 3.9.0 valgrind/3.9.0 2014-01-07
valgrind pdsf_sl6 applications/ programming 3.9.0 valgrind/3.9.0 2014-07-25 2014-07-25
valgrind phoebe applications/ programming 3.7.0 valgrind/3.7.0 2012-07-03 2013-06-26