Difference between revisions of "Valgrind"

From HPC users
Jump to navigationJump to search
(Created page with "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...")
 
 
(10 intermediate revisions by 2 users not shown)
Line 3: Line 3:


== Usage ==
== Usage ==
To use valgrind please load the actual release of valgind by
  module load valgrind


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.
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.
Line 11: Line 15:
The typical output of valgrind is very long and sometimes not easy to understand. For more informations see the  [http://valgrind.org/docs/manual/manual.html| user guide].
The typical output of valgrind is very long and sometimes not easy to understand. For more informations see the  [http://valgrind.org/docs/manual/manual.html| 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
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 output into a file with a suffix of the rank. This can be done by the command line option ''--log-file'' and the substitution ''%q{}''of valgrind. For example valgrind can be started by
 
  #!/bin/bash
  # filename: my_valgrind_run.sh
  valgrind -v --leack-check=full <mpiprogram> [program_options] >& valgrind.out.$PMI_RANK
 
for Intel MPI. When launching the script with


   mpirun -np <number_of_processes> ... my_valginrd_run.sh
   mpirun -np <number_of_processes> ... valgrind -v --leak-check=full --log-file="valgrind.out.%q{PMI_RANK}" <mpiprogram> [program_options]


the output is redirected into the files valdgrind.out.[0...<number_of_processes>] for each process.
for Intel MPI. Here the statement ''%q{PMI_RANK}'' is substituted by the value of environment variable ''PMI_RANK'' which is set by Intel MPI. For OpenMPI the variable name ''PMI_RANK'' has to be replaced by ''OMPI_COMM_WORLD_RANK''. The output is then redirected into the files valdgrind.out.[0...<number_of_processes>] for each process/rank. If for example the error occurs on rank 123 the related message can be found in the file ''valdgrind.out.123''.


'''Note''':  
'''Note''':  
* By using valgrind the runtime of the tested program increases dramatically so that the tests should be done on small problems.
* 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.
* Sometimes error messages occurs due to compiler libraries (especially Intel compiler) which are not really an error.
== Known issues ==
* Binaries build with the Intel compilers shows a lot of error messages in some libraries due to uninitialized values (e.g. in command vsprintf). These messages comes from the optimized Intel libraries and can be ignored.




== External links ==
== External links ==
* [http://valgrind.org/| Homepage of valgrind]
* [http://valgrind.org/ Homepage of valgrind]
* [http://valgrind.org/docs/manual/manual.html| User guide]
* [http://valgrind.org/docs/manual/manual.html User guide]

Latest revision as of 10:10, 9 February 2015

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 please load the actual release of valgind by

 module load valgrind

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 output into a file with a suffix of the rank. This can be done by the command line option --log-file and the substitution %q{}of valgrind. For example valgrind can be started by

 mpirun -np <number_of_processes> ... valgrind -v --leak-check=full --log-file="valgrind.out.%q{PMI_RANK}" <mpiprogram> [program_options]

for Intel MPI. Here the statement %q{PMI_RANK} is substituted by the value of environment variable PMI_RANK which is set by Intel MPI. For OpenMPI the variable name PMI_RANK has to be replaced by OMPI_COMM_WORLD_RANK. The output is then redirected into the files valdgrind.out.[0...<number_of_processes>] for each process/rank. If for example the error occurs on rank 123 the related message can be found in the file valdgrind.out.123.

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.


Known issues

  • Binaries build with the Intel compilers shows a lot of error messages in some libraries due to uninitialized values (e.g. in command vsprintf). These messages comes from the optimized Intel libraries and can be ignored.


External links