Drd And Custom Memory Allocators - Valgrind Software Quick Start Manual

Table of Contents

Advertisement

As an example, the test OpenMP test program drd/tests/omp_matinv triggers a data race when the option -r
has been specified on the command line. The data race is triggered by the following code:
#pragma omp parallel for private(j)
for (j = 0; j < rows; j++)
{
if (i != j)
{
const elem_t factor = a[j * cols + i];
for (k = 0; k < cols; k++)
{
a[j * cols + k] -= a[i * cols + k] * factor;
}
}
}
The above code is racy because the variable k has not been declared private. DRD will print the following error
message for the above code:
$ valgrind --tool=drd --check-stack-var=yes --read-var-info=yes drd/tests/omp_matinv 3 -t 2 -
...
Conflicting store by thread 1/1 at 0x7fefffbc4 size 4
at 0x4014A0: gj.omp_fn.0 (omp_matinv.c:203)
by 0x401211: gj (omp_matinv.c:159)
by 0x40166A: invert_matrix (omp_matinv.c:238)
by 0x4019B4: main (omp_matinv.c:316)
Location 0x7fefffbc4 is 0 bytes inside local var "k"
declared at omp_matinv.c:160, in frame #0 of thread 1
...
In the above output the function name gj.omp_fn.0 has been generated by GCC from the function name gj. The
allocation context information shows that the data race has been caused by modifying the variable k.
Note: for GCC versions before 4.4.0, no allocation context information is shown. With these GCC versions the most
usable information in the above output is the source file name and the line number where the data race has been
detected (omp_matinv.c:203).
For more information about OpenMP, see also openmp.org.

8.2.9. DRD and Custom Memory Allocators

DRD tracks all memory allocation events that happen via the standard memory allocation and deallocation functions
(malloc, free, new and delete), via entry and exit of stack frames or that have been annotated with Valgrind's
memory pool client requests. DRD uses memory allocation and deallocation information for two purposes:
DRD: a thread error detector
132

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Software and is the answer not in the manual?

Table of Contents