Debugging

Valgrind

Valgrind is a tool for dynamic analysis of code with features like memory profiling, thread debugging, etc...

For MPI executions the command line is formed as usual: for example on 4 processes mpirun -n 4 valgrind ...

Each MPI processus will write the trace in a separate output file.

Finding memory leaks:

valgrind --leak-check=full --show-leak-kinds=all \
  --suppressions=/usr/share/openmpi/openmpi-valgrind.supp  cimlib_CFD_driver main.mtc

The suppression file is used to remove false positives or known issues in third party libraries (such as openmpi) from the output.

Example summary:

==28099== LEAK SUMMARY:
==28099==    definitely lost: 125,082 bytes in 3,032 blocks
==28099==    indirectly lost: 2,013 bytes in 60 blocks
==28099==      possibly lost: 0 bytes in 0 blocks
==28099==    still reachable: 189,597 bytes in 1,469 blocks
==28099==         suppressed: 0 bytes in 0 blocks

Profiling heap memory:

Valgrind also provides a tool called Massif for tracing the heap memory allocations and deallocations:

valgrind --tool=massif ./bin/solver_inviscid_euler test2.exa

Trace files can be opened using the KDE application massif-visualizer: