4 merge requests!368Update prace.md to document the change from qprace to qprod as the default...,!367Update prace.md to document the change from qprace to qprod as the default...,!366Update prace.md to document the change from qprace to qprod as the default...,!323extended-acls-storage-section
@@ -4,13 +4,13 @@ Valgrind is a tool for memory debugging and profiling.
## About Valgrind
Valgrind is an open-source tool, used mainly for debuggig memory-related problems, such as memory leaks, use of uninitalized memory etc. in C/C++ applications. The toolchain was however extended over time with more functionality, such as debugging of threaded applications, cache profiling, not limited only to C/C++.
Valgrind is an open-source tool used mainly for debugging memory-related problems, such as memory leaks, use of uninitalized memory, etc. in C/C++ applications. However, the toolchain was extended over time with more functionality, such as debugging of threaded applications, cache profiling, not limited only to C/C++.
Valgind is an extremely useful tool for debugging memory errors such as [off-by-one][a]. Valgrind uses a virtual machine and dynamic recompilation of binary code, because of that, you can expect that programs being debugged by Valgrind run 5-100 times slower.
Valgind is an extremely useful tool for debugging memory errors such as [off-by-one][a]. Valgrind uses a virtual machine and dynamic recompilation of binary code, so you can expect that programs being debugged by Valgrind run 5-100 times slower.
The main tools available in Valgrind are:
The main tools available in Valgrind are:
***Memcheck**, the original, must used and default tool. Verifies memory access in you program and can detect use of unitialized memory, out of bounds memory access, memory leaks, double free, etc.
***Memcheck**, the original, most used and default tool. Verifies memory access in you program and can detect use of uninitialized memory, out of bounds memory access, memory leaks, double free, etc.
***Massif**, a heap profiler.
***Hellgrind** and **DRD** can detect race conditions in multi-threaded applications.
***Cachegrind**, a cache profiler.
...
...
@@ -26,15 +26,15 @@ There are two versions of Valgrind available on Anselm.
There are two versions of Valgrind available on the Salomon.
* Version 3.8.1, installed by operating system vendor in /usr/bin/valgrind. This version is available by default, without the need to load any module. This version however does not provide additional MPI support. Also, it does not support AVX2 instructions, debugging of an AVX2-enabled executable with this version will fail
* Version 3.11.0 built by ICC with support for Intel MPI, available in module Valgrind/3.11.0-intel-2015b. After loading the module, this version replaces the default valgrind.
* Version 3.8.1, installed by operating system vendor in /usr/bin/valgrind. This version is available by default, without the need to load any module. However, this version does not provide additional MPI support. Also, it does not support AVX2 instructions - debugging of an AVX2-enabled executable with this version will fail
* Version 3.11.0 built by ICC with support for Intel MPI, available in module Valgrind/3.11.0-intel-2015b. After loading the module, this version replaces the default Valgrind.
* Version 3.11.0 built by GCC with support for OpenMPI, module Valgrind/3.11.0-foss-2015b
## Usage
Compile the application which you want to debug as usual. It is advisable to add compilation flags -g (to add debugging information to the binary so that you will see original source code lines in the output) and -O0 (to disable compiler optimizations).
Compile the application which you want to debug as usual. It is advisable to add the compilation flags -g (to add debugging information to the binary so that you will see original source code lines in the output) and -O0 (to disable compiler optimizations).
For example, lets look at this C code, which has two problems:
For example, let us look at this C code, which has two problems:
```cpp
#include<stdlib.h>
...
...
@@ -59,11 +59,11 @@ $ module add intel
$icc -g valgrind-example.c -o valgrind-example
```
Now, lets run it with Valgrind. The syntax is :
Now, let us run it with Valgrind:
`valgrind [valgrind options] <your program binary> [your program options]`
If no Valgrind options are specified, Valgrind defaults to running Memcheck tool. Refer to the Valgrind documentation for a full description of command line options.
If no Valgrind options are specified, Valgrind defaults to running the Memcheck tool. For the full description of command line options, refer to the Valgrind documentation.
```console
$valgrind ./valgrind-example
...
...
@@ -97,7 +97,7 @@ $ valgrind ./valgrind-example
==12652== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 6)
```
In the output we can see that Valgrind has detected both errors - the off-by-one memory access at line 5 and a memory leak of 40 bytes. If we want a detailed analysis of the memory leak, we need to run Valgrind with --leak-check=full option:
In the output, we can see that Valgrind has detected both errors - the off-by-one memory access at line 5 and a memory leak of 40 bytes. If we want a detailed analysis of the memory leak, we need to run Valgrind with --leak-check=full option:
```console
$valgrind --leak-check=full ./valgrind-example
...
...
@@ -139,13 +139,13 @@ Now we can see that the memory leak is due to the malloc() at line 6.
## Usage With MPI
Although Valgrind is not primarily a parallel debugger, it can be used to debug parallel applications as well. When launching your parallel applications, prepend the valgrind command. For example:
Although Valgrind is not primarily a parallel debugger, it can be used to debug parallel applications as well. When launching your parallel applications, prepend the valgrind command. For example:
```console
$mpirun -np 4 valgrind myapplication
```
The default version without MPI support will however report a large number of false errors in the MPI library, such as:
The default version without MPI support will however report a large number of false errors in the MPI library, such as:
```console
==30166== Conditional jump or move depends on uninitialised value(s)
...
...
@@ -162,14 +162,14 @@ The default version without MPI support will however report a large number of fa
==30166== by 0x4008BD: main (valgrind-example-mpi.c:18)
```
so it is better to use the MPI-enabled valgrind from module. The MPI version requires library:
So it is better to use the MPI-enabled Valgrind from the module. The MPI version requires the library:
Prints this output : (note that there is output printed for every launched MPI process)
Prints this output (note that there is an output printed for every launched MPI process):
```console
==31318== Memcheck, a memory error detector
...
...
@@ -270,7 +270,7 @@ Prints this output : (note that there is output printed for every launched MPI p
==31319== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
```
We can see that Valgrind has reported use of uninitialized memory on the master process (which reads the array to be broadcast) and use of unaddressable memory on both processes.
We can see that Valgrind has reported use of the uninitialized memory on the master process (which reads the array to be broadcast) and use of the unaddressable memory on both processes.