File: Support_for_Debugging_Memory_Allocation.md

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (62 lines) | stat: -rw-r--r-- 2,581 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Support For Debugging Memory Allocation

## Heap Allocation Debugging

The MPICH code contains built-in support for tracing and verifying
memory allocation. To make use of this support, configure with
`--enable-g=mem` (you may combine `mem` with other debugging options,
such as `--enable-g=dbg,log,mem`).

The following environment variables, if they are set to the value `YES`
or `yes`, will change the behavior of the memory allocation routines:

  - `MPICH_TRMEM_VALIDATE`
    Validate all of the allocated memory, checking for damaged headers
    or overwritten memory sentinels, every time memory is allocated or
    freed.
  - `MPICH_TRMEM_INITZERO`
    Initialize allocated and freed memory to zero. Normally, the memory
    is initialized to `0xda` to help detect references to uninitialized
    memory. Freed memory is filled with `0xfc` to help detect
    reads/writes from/to deallocated memory.

During `MPI_Finalize`, any memory allocated but not freed will be
written out.

## Handle Allocation Debugging

MPICH also contains separate facilities for allocating object handles
(such as `MPI_Comm`'s) and the associated underlying object. Similarly,
these facilities have debugging code to help with memory errors that is
enabled via `--enable-g=mem`. You should also add `meminit` if you
intend to debug with valgrind ([see below](#valgrind-integration))

Newly allocated handles will be filled with `0xef`. Freed handles will
be filled with `0xec`.

## Valgrind Integration

The old version of the memory debugging code interfered with valgrind's
ability to detect uninitialized data. As of  MPICH contains 
[Valgrind Client Requests](http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq)
to prevent this problem when configured with `--enable-g=meminit`.

If `valgrind.h` and `memcheck.h` are not in your default path you will
need to add that include path to your configure line.

```
 ./configure [your_args_here] --enable-g=meminit CPPFLAGS='-I/path/to/valgrind/includes'
```

For example:

```
 ./configure --prefix=/sandbox/goodell/mpich-installed --enable-g=dbg,mem,meminit CPPFLAGS='-I/usr/include/valgrind'
```

If configure can't find these two headers then valgrind may not report
certain types of errors when `--enable-g=mem` is specified. Also, if you
intend to use valgrind with MPICH you should generally configure with
`--enable-g=dbg,meminit` at the very least. This will get you stack
traces and prevent several known false positives from being reported as
well as the false negative prevention that has been mentioned.