<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>The backtrace is</p>
    <p><span style="font-family:monospace"><span style="color:#000000;background-color:#ffffff;">#0  </span><span style="color:#1818b2;background-color:#ffffff;">0x00007fffeec4ba97</span><span style="color:#000000;background-color:#ffffff;"> in </span><span style="color:#b26818;background-color:#ffffff;">VecGetSize_Seq</span><span style="color:#000000;background-color:#ffffff;"> () from </span><span style="color:#18b218;background-color:#ffffff;">/opt/petsc/lib/libpetsc.so.3.016</span><span style="color:#000000;background-color:#ffffff;">
        </span><br>
        #1  <span style="color:#1818b2;background-color:#ffffff;">0x00007fffeec78f5a</span><span style="color:#000000;background-color:#ffffff;"> in </span><span style="color:#b26818;background-color:#ffffff;">VecGetSize</span><span style="color:#000000;background-color:#ffffff;"> () from </span><span style="color:#18b218;background-color:#ffffff;">/opt/petsc/lib/libpetsc.so.3.016</span><span style="color:#000000;background-color:#ffffff;">
        </span><br>
        #2  <span style="color:#1818b2;background-color:#ffffff;">0x0000000000410b73</span><span style="color:#000000;background-color:#ffffff;"> in </span><span style="color:#b26818;background-color:#ffffff;">test_ts_arma_with_pure_petsc_preconfigured_clean(unsigned
          long, unsigned long, arma::Col<std::complex<doubl</span><br>
        e> > const&, arma::Col<std::complex<double>
        >&, double, double, double) [clone .constprop.0]<span style="color:#000000;background-color:#ffffff;"> ()
        </span><br>
        #3  <span style="color:#1818b2;background-color:#ffffff;">0x0000000000414384</span><span style="color:#000000;background-color:#ffffff;"> in </span><span style="color:#b26818;background-color:#ffffff;">test_RK4_solvers_clean(unsigned
          long, unsigned long, unsigned long, bool) [clone .constprop.0]</span><span style="color:#000000;background-color:#ffffff;"> ()
        </span><br>
        #4  <span style="color:#1818b2;background-color:#ffffff;">0x0000000000405c6c</span><span style="color:#000000;background-color:#ffffff;"> in </span><span style="color:#b26818;background-color:#ffffff;">main</span><span style="color:#000000;background-color:#ffffff;"> ()</span></span></p>
    <p>Regards,</p>
    <div class="moz-cite-prefix">Roland Richter</div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Am 31.03.22 um 15:35 schrieb Matthew
      Knepley:<br>
    </div>
    <blockquote type="cite" cite="mid:CAMYG4Gnh_=nbwFH-C9BkUSg73KMkXe+Z3NgmDwF923_U23vyZQ@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">On Thu, Mar 31, 2022 at 9:01 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>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>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><br>
          </div>
          <div>  Thanks,</div>
          <div><br>
          </div>
          <div>    Matt</div>
          <div> <br>
          </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>Regards,</p>
              <p>Roland Richter<br>
              </p>
              <div>Am 31.03.22 um 12:14 schrieb Matthew Knepley:<br>
              </div>
              <blockquote type="cite">
                <div dir="ltr">
                  <div dir="ltr">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>
                  </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">
                    <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>
            </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>