[petsc-users] Discrepancy between valgrind and -malloc_dump output

Zane Charles Jakobs Zane.Jakobs at colorado.edu
Mon Mar 9 14:46:32 CDT 2020


Hi PETSc devs,

I have a C++ program written with PETSc (code available at
https://github.com/DiffeoInvariant/NLTS/blob/master/examples/mutual_opt.cpp),
and if I run it with -malloc_debug and -malloc_dump enabled, PETSc says no
memory is left unfreed at exit. However, running with valgrind
--leak-check=full --show-leak-kinds=all gives me this leak summary:

LEAK SUMMARY:
==15364==    definitely lost: 0 bytes in 0 blocks
==15364==    indirectly lost: 0 bytes in 0 blocks
==15364==      possibly lost: 0 bytes in 0 blocks
==15364==    still reachable: 610,904 bytes in 8,246 blocks
==15364==         suppressed: 0 bytes in 0 blocks

The information from --show-leak-kinds=all gives several blocks of the form
(this is the last block printed; I've attached the full output from
valgrind to this email)

==15364== 329,080 bytes in 3 blocks are still reachable in loss record 7 of
7
==15364==    at 0x483CFAF: realloc (in
/usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==15364==    by 0x7BDE1A7: ??? (in
/usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==15364==    by 0x7BDE41C: ??? (in
/usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==15364==    by 0x7BDE579: pci_device_get_device_name (in
/usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==15364==    by 0x759CFC4: hwloc_look_pci (in
/usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==15364==    by 0x7571D0B: hwloc_discover (in
/usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==15364==    by 0x7571637: hwloc_topology_load (in
/usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==15364==    by 0x736780A: MPIR_Init_thread (in
/usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==15364==    by 0x7367435: PMPI_Init_thread (in
/usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==15364==    by 0x491CABA: PetscInitialize (in
/usr/local/petsc/arch-linux-cxx-debug/lib/libpetsc.so.3.012.4)
==15364==    by 0x724AB0E: nlts::io::Initialize(int*, char***, char const*,
char const*) (io.cpp:126)
==15364==    by 0x4023CB: main (mutual_opt.cpp:30)

The function nlts::io::Initialize that's referenced at the bottom is simply

PetscErrorCode nlts::io::Initialize(int *argc, char ***argv,
const char file[],
const char help[])
{
PetscFunctionBeginUser;
auto ierr = PetscInitialize(argc, argv, file, help);CHKERRQ(ierr);
PetscFunctionReturn(ierr);
}

Is valgrind actually detecting unfreed memory here, or is this something I
don't need to worry about?

Thanks!

-Zane Jakobs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200309/778c17fe/attachment-0001.html>
-------------- next part --------------
==16115== Memcheck, a memory error detector
==16115== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16115== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==16115== Command: ../bin/mutual-opt -f trajectory_data_1/data_x.dat -o mutual_info.txt -D 300 -malloc_debug -malloc_dump
==16115== 
Minimizing mutual information.
Tau that minimizes mutual information: 153.
WARNING! There are options you set that were not used!
WARNING! could be spelling mistake, etc!
There is one unused database option. It is:
Option left: name:-malloc_debug (no value)
==16115== 
==16115== HEAP SUMMARY:
==16115==     in use at exit: 610,904 bytes in 8,246 blocks
==16115==   total heap usage: 19,334 allocs, 11,069 frees, 1,134,882,918 bytes allocated
==16115== 
==16115== 76 bytes in 3 blocks are still reachable in loss record 1 of 7
==16115==    at 0x483A7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==16115==    by 0x77A353E: strdup (strdup.c:42)
==16115==    by 0x7BDE371: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE469: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x759CF76: hwloc_look_pci (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571D0B: hwloc_discover (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571637: hwloc_topology_load (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x736780A: MPIR_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7367435: PMPI_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x491CABA: PetscInitialize (in /usr/local/petsc/arch-linux-cxx-debug/lib/libpetsc.so.3.012.4)
==16115==    by 0x724AB0E: nlts::io::Initialize(int*, char***, char const*, char const*) (io.cpp:126)
==16115==    by 0x4023CB: main (mutual_opt.cpp:30)
==16115== 
==16115== 96 bytes in 3 blocks are still reachable in loss record 2 of 7
==16115==    at 0x483CD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==16115==    by 0x7BDDF86: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE43D: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x759CF76: hwloc_look_pci (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571D0B: hwloc_discover (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571637: hwloc_topology_load (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x736780A: MPIR_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7367435: PMPI_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x491CABA: PetscInitialize (in /usr/local/petsc/arch-linux-cxx-debug/lib/libpetsc.so.3.012.4)
==16115==    by 0x724AB0E: nlts::io::Initialize(int*, char***, char const*, char const*) (io.cpp:126)
==16115==    by 0x4023CB: main (mutual_opt.cpp:30)
==16115== 
==16115== 136 bytes in 1 blocks are still reachable in loss record 3 of 7
==16115==    at 0x483CD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==16115==    by 0x7BDDFAE: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE43D: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x759CF76: hwloc_look_pci (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571D0B: hwloc_discover (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571637: hwloc_topology_load (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x736780A: MPIR_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7367435: PMPI_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x491CABA: PetscInitialize (in /usr/local/petsc/arch-linux-cxx-debug/lib/libpetsc.so.3.012.4)
==16115==    by 0x724AB0E: nlts::io::Initialize(int*, char***, char const*, char const*) (io.cpp:126)
==16115==    by 0x4023CB: main (mutual_opt.cpp:30)
==16115== 
==16115== 1,224 bytes in 9 blocks are still reachable in loss record 4 of 7
==16115==    at 0x483CD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==16115==    by 0x7BDDF52: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE43D: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x759CF76: hwloc_look_pci (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571D0B: hwloc_discover (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571637: hwloc_topology_load (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x736780A: MPIR_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7367435: PMPI_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x491CABA: PetscInitialize (in /usr/local/petsc/arch-linux-cxx-debug/lib/libpetsc.so.3.012.4)
==16115==    by 0x724AB0E: nlts::io::Initialize(int*, char***, char const*, char const*) (io.cpp:126)
==16115==    by 0x4023CB: main (mutual_opt.cpp:30)
==16115== 
==16115== 104,012 bytes in 4,245 blocks are still reachable in loss record 5 of 7
==16115==    at 0x483A7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==16115==    by 0x77A353E: strdup (strdup.c:42)
==16115==    by 0x7BDE220: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE41C: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE579: pci_device_get_device_name (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x759CFC4: hwloc_look_pci (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571D0B: hwloc_discover (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571637: hwloc_topology_load (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x736780A: MPIR_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7367435: PMPI_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x491CABA: PetscInitialize (in /usr/local/petsc/arch-linux-cxx-debug/lib/libpetsc.so.3.012.4)
==16115==    by 0x724AB0E: nlts::io::Initialize(int*, char***, char const*, char const*) (io.cpp:126)
==16115== 
==16115== 176,280 bytes in 3,982 blocks are still reachable in loss record 6 of 7
==16115==    at 0x483A7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==16115==    by 0x77A353E: strdup (strdup.c:42)
==16115==    by 0x7BDE317: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE41C: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE579: pci_device_get_device_name (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x759CFC4: hwloc_look_pci (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571D0B: hwloc_discover (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571637: hwloc_topology_load (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x736780A: MPIR_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7367435: PMPI_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x491CABA: PetscInitialize (in /usr/local/petsc/arch-linux-cxx-debug/lib/libpetsc.so.3.012.4)
==16115==    by 0x724AB0E: nlts::io::Initialize(int*, char***, char const*, char const*) (io.cpp:126)
==16115== 
==16115== 329,080 bytes in 3 blocks are still reachable in loss record 7 of 7
==16115==    at 0x483CFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==16115==    by 0x7BDE1A7: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE41C: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x7BDE579: pci_device_get_device_name (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)
==16115==    by 0x759CFC4: hwloc_look_pci (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571D0B: hwloc_discover (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7571637: hwloc_topology_load (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x736780A: MPIR_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x7367435: PMPI_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)
==16115==    by 0x491CABA: PetscInitialize (in /usr/local/petsc/arch-linux-cxx-debug/lib/libpetsc.so.3.012.4)
==16115==    by 0x724AB0E: nlts::io::Initialize(int*, char***, char const*, char const*) (io.cpp:126)
==16115==    by 0x4023CB: main (mutual_opt.cpp:30)
==16115== 
==16115== LEAK SUMMARY:
==16115==    definitely lost: 0 bytes in 0 blocks
==16115==    indirectly lost: 0 bytes in 0 blocks
==16115==      possibly lost: 0 bytes in 0 blocks
==16115==    still reachable: 610,904 bytes in 8,246 blocks
==16115==         suppressed: 0 bytes in 0 blocks
==16115== 
==16115== For lists of detected and suppressed errors, rerun with: -s
==16115== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


More information about the petsc-users mailing list