<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hei,</p>
<p>It defines the namespace used for armadillo-matrices. A
valgrind-log is attached for the case with removed destructor
(can't run valgrind if my program fails with a segfault).<br>
</p>
<p>Regards,</p>
<p>Roland<br>
</p>
<div class="moz-cite-prefix">Am 01.04.22 um 15:23 schrieb Barry
Smith:<br>
</div>
<blockquote type="cite" cite="mid:6C65CC1D-365D-43AE-B159-AFB3DCF3D4C0@petsc.dev">
<div class=""><br class="">
</div>
I recommend first running with valgrind.
<div class=""><br class="">
</div>
<div class=""> I tried to build your code but got compile errors
from arma:: being unknown. Where does it come from? Is it only
in a super new version of Boost?</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Apr 1, 2022, at 6:50 AM, Roland Richter
<<a href="mailto:roland.richter@ntnu.no" class="moz-txt-link-freetext" moz-do-not-send="true">roland.richter@ntnu.no</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">
<p class="">I re-run my code with a debug version of
PETSc, resulting in <br class="">
</p>
<p class=""><span style="font-family:monospace" class=""><span style="font-weight:bold;color:#ff5454;background-color:#ffffff;" class="">[0]PETSC ERROR: ---------------------
Error Message
--------------------------------------------------------------</span><span style="background-color: rgb(255, 255, 255);" class=""> </span><br class="">
[0]PETSC ERROR: Corrupt argument: <a class="moz-txt-link-freetext" href="https://petsc.org/release/faq/#valgrind" moz-do-not-send="true">https://petsc.org/release/faq/#valgrind</a>
<br class="">
[0]PETSC ERROR: Object already free: Parameter # 1 <br class="">
[0]PETSC ERROR: See <a class="moz-txt-link-freetext" href="https://petsc.org/release/faq/" moz-do-not-send="true">https://petsc.org/release/faq/</a>
for trouble shooting. <br class="">
[0]PETSC ERROR: Petsc Development GIT revision:
v3.17.0-8-gf6d6129e50 GIT Date: 2022-03-31 18:10:33
+0000 <br class="">
[0]PETSC ERROR: #1 VecGetSize() at
/home/roland/Downloads/git-files/petsc/src/vec/vec/interface/vector.c:670<br class="">
0 64 <br class="">
[0]PETSC ERROR: #2 VecDestroy() at
/home/roland/Downloads/git-files/petsc/src/vec/vec/interface/vector.c:375<br class="">
0 64 <br class="">
[0]PETSC ERROR: #3 VecGetArray() at
/home/roland/Downloads/git-files/petsc/src/vec/vec/interface/rvector.c:1780<br class="">
<br class="">
</span></p>
<p class="">I do not understand why it tries to access
the vector, even though it has been set to PETSC_NULL
in the previous free-call.</p>
<p class="">Regards,</p>
<p class="">Roland<br class="">
</p>
<div class="moz-cite-prefix">Am 31.03.22 um 15:50
schrieb Matthew Knepley:<br class="">
</div>
<blockquote type="cite" cite="mid:CAMYG4GnoJnQmGeCTiBZoN6QMXw5bNm+EbM0-P_DzM2S45UyxVQ@mail.gmail.com" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">On Thu, Mar 31, 2022 at 9:47
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 class="">
</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 class="">
<p class="">The backtrace is</p>
<p class=""><span style="font-family:monospace" class=""><span style="background-color: rgb(255, 255,
255);" class="">#0 </span><span style="color:rgb(24,24,178);background-color:rgb(255,255,255)" class="">0x00007fffeec4ba97</span><span style="background-color: rgb(255, 255,
255);" class=""> in </span><span style="color:rgb(178,104,24);background-color:rgb(255,255,255)" class="">VecGetSize_Seq</span><span style="background-color: rgb(255, 255,
255);" class=""> () from </span><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)" class="">/opt/petsc/lib/libpetsc.so.3.016</span><span style="background-color: rgb(255, 255,
255);" class=""> </span><br class="">
#1 <span style="color:rgb(24,24,178);background-color:rgb(255,255,255)" class="">0x00007fffeec78f5a</span><span style="background-color: rgb(255, 255,
255);" class=""> in </span><span style="color:rgb(178,104,24);background-color:rgb(255,255,255)" class="">VecGetSize</span><span style="background-color: rgb(255, 255,
255);" class=""> () from </span><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)" class="">/opt/petsc/lib/libpetsc.so.3.016</span><span style="background-color: rgb(255, 255,
255);" class=""> </span><br class="">
#2 <span style="color:rgb(24,24,178);background-color:rgb(255,255,255)" class="">0x0000000000410b73</span><span style="background-color: rgb(255, 255,
255);" class=""> in </span><span style="color:rgb(178,104,24);background-color:rgb(255,255,255)" class="">test_ts_arma_with_pure_petsc_preconfigured_clean(unsigned
long, unsigned long,
arma::Col<std::complex<doubl</span><br class="">
e> > const&,
arma::Col<std::complex<double>
>&, double, double, double) [clone
.constprop.0]<span style="background-color: rgb(255, 255,
255);" class=""> () </span><br class="">
#3 <span style="color:rgb(24,24,178);background-color:rgb(255,255,255)" class="">0x0000000000414384</span><span style="background-color: rgb(255, 255,
255);" class=""> in </span><span style="color:rgb(178,104,24);background-color:rgb(255,255,255)" class="">test_RK4_solvers_clean(unsigned
long, unsigned long, unsigned long,
bool) [clone .constprop.0]</span><span style="background-color: rgb(255, 255,
255);" class=""> () </span><br class="">
#4 <span style="color:rgb(24,24,178);background-color:rgb(255,255,255)" class="">0x0000000000405c6c</span><span style="background-color: rgb(255, 255,
255);" class=""> in </span><span style="color:rgb(178,104,24);background-color:rgb(255,255,255)" class="">main</span><span style="background-color: rgb(255, 255,
255);" class=""> ()</span></span></p>
</div>
</blockquote>
<div class="">It looks like you are passing an
invalid vector. If you compiled in debug mode,
it would tell you. I would run</div>
<div class="">in debug until my code was running
like I expect, then switch to optimized. You can
do that by using two</div>
<div class="">different PETSC_ARCH configures, and
switch at runtime with that variable.</div>
<div class=""><br class="">
</div>
<div class=""> Thanks,</div>
<div class=""><br class="">
</div>
<div class=""> 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 class="">
<p class="">Regards,</p>
<div class="">Roland Richter</div>
<div class=""><br class="">
</div>
<div class="">Am 31.03.22 um 15:35 schrieb
Matthew Knepley:<br class="">
</div>
<blockquote type="cite" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">On Thu, Mar 31,
2022 at 9:01 AM Roland Richter <<a href="mailto:roland.richter@ntnu.no" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">roland.richter@ntnu.no</a>>
wrote:<br class="">
</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 class="">
<p class="">Hei,</p>
<p class="">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>
</div>
</blockquote>
<div class="">Run with
-start_in_debugger and get the stack
trace when it faults. Right now, I
have no idea where it is faulting.</div>
<div class=""><br class="">
</div>
<div class=""> Thanks,</div>
<div class=""><br class="">
</div>
<div class=""> Matt</div>
<div class=""> <br class="">
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div class="">
<p class="">Regards,</p>
<p class="">Roland Richter<br class="">
</p>
<div class="">Am 31.03.22 um 12:14
schrieb Matthew Knepley:<br class="">
</div>
<blockquote type="cite" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">On Thu,
Mar 31, 2022 at 5:58 AM Roland
Richter <<a href="mailto:roland.richter@ntnu.no" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">roland.richter@ntnu.no</a>>
wrote:<br class="">
</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 class="">
<p class="">Hei,</p>
<p class="">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 class="">main.cpp</b>,
and the test code in <b class="">test_timestepping_clean.cpp</b>)<br class="">
</p>
<p class="">In theory, the
code works fine, but I
have some issues with
cleaning up afterwards
in my struct <i class="">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 class="">PETSC_NULL</i>,
and check if this value
has been changed before
calling <i class="">VecDestroy().</i></p>
</div>
</blockquote>
<div class="">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 class="">
<p class=""> However, when
doing that I get the
following error:</p>
<p class=""><span style="font-family:monospace" class=""><span style="background-color:
rgb(255, 255, 255);" class="">[0]PETSC
ERROR:
------------------------------------------------------------------------
</span><br class="">
[0]PETSC ERROR: Caught
signal number 11 SEGV:
Segmentation
Violation, probably
memory access out of
range <br class="">
[0]PETSC ERROR: Try
option
-start_in_debugger or
-on_error_attach_debugger <br class="">
[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 class="">
[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 class="">
[0]PETSC ERROR:
configure using
--with-debugging=yes,
recompile, link, and
run <br class="">
[0]PETSC ERROR: to get
more information on
the crash. <br class="">
<span style="font-weight:bold;color:rgb(255,84,84);background-color:rgb(255,255,255)" class="">[0]PETSC
ERROR:
---------------------
Error Message
--------------------------------------------------------------</span></span></p>
<p class="">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 class="">It must be that
your constructor is called
multiple times without
calling your destructor. I
cannot understand this code
in order</div>
<div class="">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 class="">
</div>
<div class="">destruction
calls.</div>
<div class=""><br class="">
</div>
<div class=""> Thanks,</div>
<div class=""><br class="">
</div>
<div class=""> 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 class="">
<p class="">Thanks!</p>
<p class="">Regards,</p>
<p class="">Roland Richter<br class="">
</p>
<div class=""><span style="font-family:monospace" class=""></span><br class="webkit-block-placeholder">
</div>
</div>
</blockquote>
</div>
<br class="" clear="all">
<div class=""><br class="">
</div>
-- <br class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">What
most experimenters
take for granted
before they begin
their experiments
is infinitely more
interesting than
any results to
which their
experiments lead.<br class="">
-- Norbert Wiener</div>
<div class=""><br class="">
</div>
<div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" moz-do-not-send="true" class="">https://www.cse.buffalo.edu/~knepley/</a><br class="">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
<br class="" clear="all">
<div class=""><br class="">
</div>
-- <br class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">What most
experimenters take for
granted before they begin
their experiments is
infinitely more interesting
than any results to which
their experiments lead.<br class="">
-- Norbert Wiener</div>
<div class=""><br class="">
</div>
<div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" moz-do-not-send="true" class="">https://www.cse.buffalo.edu/~knepley/</a><br class="">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
<br class="" clear="all">
<div class=""><br class="">
</div>
-- <br class="">
<div dir="ltr" class="gmail_signature">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">
<div dir="ltr" class="">
<div class="">What most experimenters
take for granted before they begin
their experiments is infinitely more
interesting than any results to which
their experiments lead.<br class="">
-- Norbert Wiener</div>
<div class=""><br class="">
</div>
<div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" moz-do-not-send="true" class="">https://www.cse.buffalo.edu/~knepley/</a><br class="">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</blockquote>
</body>
</html>