[petsc-users] Memory leak when combining PETSc-based vectors and boost::odeint

Roland Richter roland.richter at ntnu.no
Thu Mar 31 04:41:09 CDT 2022


Hei,

For a project I wanted to combine boost::odeint for timestepping and
PETSc-based vectors and matrices for calculating the right hand side. As
comparison for both timing and correctness I set up an armadillo-based
right hand side (with the main-function being in *main.cpp*, and the
test code in *test_timestepping_clean.cpp*)

In theory, the code works fine, but I have some issues with cleaning up
afterwards in my struct /Petsc_RHS_state_clean/. My initial intention
was to set up all involved matrices and vectors within the constructor,
and free the memory in the destructor. To avoid freeing vectors I have
not used I initially set them to /PETSC_NULL/, and check if this value
has been changed before calling /VecDestroy()./ However, when doing that
I get the following error:

[0]PETSC ERROR:
------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation,
probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://petsc.org/release/faq/#valgrind
[0]PETSC ERROR: or try http://valgrind.org on GNU/linux and Apple Mac OS
X to find memory corruption errors
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link,
and run  
[0]PETSC ERROR: to get more information on the crash.
[0]PETSC ERROR: --------------------- Error Message
--------------------------------------------------------------

If I comment out that code in ~Petsc_RHS_state_clean(), the program
runs, but will use ~17 GByte of RAM during runtime. As the memory is not
used immediately in full, but rather increases during running, I assume
a memory leak somewhere. Where does it come from, and how can I avoid it?

Thanks!

Regards,

Roland Richter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220331/2939d323/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 601 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220331/2939d323/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_timestepping_clean.cpp
Type: text/x-c++src
Size: 9613 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220331/2939d323/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_timestepping_clean.hpp
Type: text/x-c++hdr
Size: 483 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220331/2939d323/attachment-0002.bin>


More information about the petsc-users mailing list