Valgrind

From HPC users
Revision as of 11:38, 11 December 2012 by Witha (talk | contribs) (→‎Usage)
Jump to navigationJump to search

The program valgrind is a tool to detect memory leaks and violations in a program. It tracks the allocated memory and checks if it was freed. Additionally it checks if a programm writes outside its allocated memory or threads writes at the same time to the same memory.


Usage

To use valgrind the code should be compiled with debug symbols (-g option for most of the compilers) so that errors could be backtraced to the source code line. After compiling the program will be started with valgrind typically by

 valgrind -v --leack-check=full <program> [program_options] >& valgrind.out

The typical output of valgrind is very long and sometimes not easy to understand. For more informations see the user guide.

For analyzing parallel MPI programs the mpirun/mpiexec statement including its options must precede the command line above. In this case it could be useful to write the command line above into a small shell script and pipe the output into a file with a suffix of the rank. For example

 #!/bin/bash
 # filename: my_valgrind_run.sh
 valgrind -v --leak-check=full <mpiprogram> [program_options] >& valgrind.out.$MPI_RANK

for Intel MPI. When launching the script with

 mpirun -np <number_of_processes> ...  my_valgrind_run.sh

the output is redirected into the files valdgrind.out.[0...<number_of_processes>] for each process.

Note:

  • By using valgrind the runtime of the tested program increases dramatically so that the tests should be done on small problems.
  • Sometimes error messages occurs due to compiler libraries (especially Intel compiler) which are not really an error.

External links