<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hei,</p>
<p>Thanks for the idea! I added a simple std::cout for both
constructor and destructor, and found out that my destructor is
called multiple times, while the constructor is called only once.
This could explain the error (double free), but I do not know why
segfault is thrown even though I explicitly check if the vector
has been used. Are there explanations for that?</p>
<p>Regards,</p>
<p>Roland Richter<br>
</p>
<div class="moz-cite-prefix">Am 31.03.22 um 12:14 schrieb Matthew
Knepley:<br>
</div>
<blockquote type="cite" cite="mid:CAMYG4GkDS3Wwcud9g2JhuJyPsSE9K1ff5ZMKQ1yXaDqFGT4Ybw@mail.gmail.com">
<div dir="ltr">
<div dir="ltr">On Thu, Mar 31, 2022 at 5:58 AM Roland Richter
<<a href="mailto:roland.richter@ntnu.no" moz-do-not-send="true" class="moz-txt-link-freetext">roland.richter@ntnu.no</a>>
wrote:<br>
</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<p>Hei,</p>
<p>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 <b>main.cpp</b>,
and the test code in <b>test_timestepping_clean.cpp</b>)<br>
</p>
<p>In theory, the code works fine, but I have some issues
with cleaning up afterwards in my struct <i>Petsc_RHS_state_clean</i>.
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 <i>PETSC_NULL</i>, and
check if this value has been changed before calling <i>VecDestroy().</i></p>
</div>
</blockquote>
<div>You do not need to check. Destroy() functions already
check for NULL.</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<p> However, when doing that I get the following error:</p>
<p><span style="font-family:monospace"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">[0]PETSC
ERROR:
------------------------------------------------------------------------
</span><br>
[0]PETSC ERROR: Caught signal number 11 SEGV:
Segmentation Violation, probably memory access out of
range <br>
[0]PETSC ERROR: Try option -start_in_debugger or
-on_error_attach_debugger <br>
[0]PETSC ERROR: or see <a href="https://petsc.org/release/faq/#valgrind" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">https://petsc.org/release/faq/#valgrind</a>
<br>
[0]PETSC ERROR: or try <a href="http://valgrind.org" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">http://valgrind.org</a>
on GNU/linux and Apple Mac OS X to find memory
corruption errors <br>
[0]PETSC ERROR: configure using --with-debugging=yes,
recompile, link, and run <br>
[0]PETSC ERROR: to get more information on the crash.
<br>
<span style="font-weight:bold;color:rgb(255,84,84);background-color:rgb(255,255,255)">[0]PETSC
ERROR: --------------------- Error Message
--------------------------------------------------------------</span></span></p>
<p>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?</p>
</div>
</blockquote>
<div>It must be that your constructor is called multiple times
without calling your destructor. I cannot understand this
code in order</div>
<div>to see where that happens, but you should just be able to
run in the debugger and put a break point at the creation
and<br>
</div>
<div>destruction calls.</div>
<div><br>
</div>
<div> Thanks,</div>
<div><br>
</div>
<div> Matt</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<p>Thanks!</p>
<p>Regards,</p>
<p>Roland Richter<br>
</p>
<p><span style="font-family:monospace"></span></p>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>What most experimenters take for granted before
they begin their experiments is infinitely more
interesting than any results to which their
experiments lead.<br>
-- Norbert Wiener</div>
<div><br>
</div>
<div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" moz-do-not-send="true">https://www.cse.buffalo.edu/~knepley/</a><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</body>
</html>