<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Thanks Matt,</p>
    <p>I got it figured out.  As with a lot of uninitialised value bugs
      it started a long way away (in a scalar value) and propagated
      through.  What is slightly bizarre is that valgrind didn't pick it
      up where I define and first use it, even with --track-origins=yes.<br>
    </p>
    <p>Thank you for your help.</p>
    <p>Phil<br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 26/10/2018 15:01, Matthew Knepley
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAMYG4GmESp2aEf0687VninbjEhZC+Z0WX0FOi=1QRYr6sYnACA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div class="gmail_quote">
          <div dir="ltr">On Fri, Oct 26, 2018 at 9:54 AM Phil Tooley
            <<a href="mailto:phil.tooley@sheffield.ac.uk"
              moz-do-not-send="true">phil.tooley@sheffield.ac.uk</a>>
            wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All,<br>
            <br>
            Running valgrind over my code reveals a huge number (it
            stops collecting<br>
            after 1e6) of uninitialised value errors occuring the
            KSPSolve routine. <br>
            These don't occur with the ksp example scripts but I can't
            figure out<br>
            what I am doing wrong in my code.  My code works as
            expected.  The same<br>
            errors occur with both version 3.9.4 and 3.10.0.<br>
            <br>
            I am developing in c++ and using smart pointers to allow
            autodestruction<br>
            of Petsc objects, but I don't think this should have any
            side effects. <br>
          </blockquote>
          <div><br>
          </div>
          <div>From casual inspection, it sure seems like the matrix you
            are passing KSP has unitialized</div>
          <div>values.</div>
          <div><br>
          </div>
          <div><Editorial comment>I used smart pointers for years,
            and work on packages that had smart</div>
          <div>pointers. In almost every case, we ended up ripping out
            the smart pointers and going with</div>
          <div>explicit destruction, the amount of work they save never
            outweighed the problems with</div>
          <div>detecting errors</Editorial comment></div>
          <div><br>
          </div>
          <div>  Thanks,</div>
          <div><br>
          </div>
          <div>     Matt</div>
          <div><br>
          </div>
          <div>  Thanks,</div>
          <div><br>
          </div>
          <div>    Matt</div>
          <div> </div>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            I do the ksp setup as:<br>
            <br>
            KSP_unique m_ksp = create_unique_ksp();<br>
            <br>
            perr = KSPCreate(m_comm, m_ksp.get());CHKERRABORT(m_comm,
            perr);<br>
            <br>
            perr = KSPSetOperators(*m_ksp, *normmat,
            *normmat);CHKERRABORT(m_comm,<br>
            perr);<br>
            perr = KSPSetUp(*m_ksp);CHKERRABORT(m_comm, perr);<br>
            <br>
            perr = KSPSetFromOptions(*m_ksp);CHKERRABORT(m_comm, perr);<br>
            perr = KSPSetUp(*m_ksp);CHKERRABORT(m_comm, perr);<br>
            <br>
            perr = KSPSolve(*m_ksp, *m_rhs,
            *m_delta);CHKERRABORT(m_comm, perr);<br>
            <br>
            Where normmat is a smart pointer to a previously created Mat
            object and<br>
            m_rhs and m_delta are smart pointers to Vec objects which
            are<br>
            initialised using MatCreateVecs on normmat.<br>
            <br>
            I am using MPICH to provide a (hopefully) valgrind clean MPI
            implementation.<br>
            <br>
            Any insights are appreciated.<br>
            <br>
            Many Thanks<br>
            <br>
            Phil Tooley<br>
            <br>
            Typical errors are as follows:<br>
            <br>
            ==7368== Conditional jump or move depends on uninitialised
            value(s)<br>
            ==7368==    at 0x58894EE: PetscAbsScalar(double)
            (petscmath.h:389)<br>
            ==7368==    by 0x5891702: MatLUFactorNumeric_SeqAIJ
            (aijfact.c:553)<br>
            ==7368==    by 0x5406B83: MatLUFactorNumeric (matrix.c:3031)<br>
            ==7368==    by 0x609F317: PCSetUp_ILU(_p_PC*) (ilu.c:176)<br>
            ==7368==    by 0x6192D4F: PCSetUp (precon.c:923)<br>
            ==7368==    by 0x62EAE56: KSPSetUp (itfunc.c:381)<br>
            ==7368==    by 0x60190BB:
            PCSetUpOnBlocks_BJacobi_Singleblock(_p_PC*)<br>
            (bjacobi.c:621)<br>
            ==7368==    by 0x619352C: PCSetUpOnBlocks (precon.c:954)<br>
            ==7368==    by 0x62E8F0A: KSPSetUpOnBlocks (itfunc.c:213)<br>
            ==7368==    by 0x62ECCB1: KSPSolve (itfunc.c:613)<br>
            ==7368==    by 0x10FCDD: Elastic::innerstep(double) (in<br>
            /home/telemin/repos/pfire_petsc/bin/pfire)<br>
            ==7368==    by 0x110600: Elastic::innerloop(int) (in<br>
            /home/telemin/repos/pfire_petsc/bin/pfire)<br>
            ==7368==<br>
            ==7368== Conditional jump or move depends on uninitialised
            value(s)<br>
            ==7368==    at 0x58894EE: PetscAbsScalar(double)
            (petscmath.h:389)<br>
            ==7368==    by 0x588A75F: MatPivotCheck_none(_p_Mat*,
            _p_Mat*,<br>
            MatFactorInfo const*, FactorShiftCtx*, int) (matimpl.h:704)<br>
            ==7368==    by 0x588AD6E: MatPivotCheck(_p_Mat*, _p_Mat*,
            MatFactorInfo<br>
            const*, FactorShiftCtx*, int) (matimpl.h:727)<br>
            ==7368==    by 0x589177D: MatLUFactorNumeric_SeqAIJ
            (aijfact.c:558)<br>
            ==7368==    by 0x5406B83: MatLUFactorNumeric (matrix.c:3031)<br>
            ==7368==    by 0x609F317: PCSetUp_ILU(_p_PC*) (ilu.c:176)<br>
            ==7368==    by 0x6192D4F: PCSetUp (precon.c:923)<br>
            ==7368==    by 0x62EAE56: KSPSetUp (itfunc.c:381)<br>
            ==7368==    by 0x60190BB:
            PCSetUpOnBlocks_BJacobi_Singleblock(_p_PC*)<br>
            (bjacobi.c:621)<br>
            ==7368==    by 0x619352C: PCSetUpOnBlocks (precon.c:954)<br>
            ==7368==    by 0x62E8F0A: KSPSetUpOnBlocks (itfunc.c:213)<br>
            ==7368==    by 0x62ECCB1: KSPSolve (itfunc.c:613)<br>
            ==7368==<br>
            ==7368== Conditional jump or move depends on uninitialised
            value(s)<br>
            ==7368==    at 0x588A76D: MatPivotCheck_none(_p_Mat*,
            _p_Mat*,<br>
            MatFactorInfo const*, FactorShiftCtx*, int) (matimpl.h:704)<br>
            ==7368==    by 0x588AD6E: MatPivotCheck(_p_Mat*, _p_Mat*,
            MatFactorInfo<br>
            const*, FactorShiftCtx*, int) (matimpl.h:727)<br>
            ==7368==    by 0x589177D: MatLUFactorNumeric_SeqAIJ
            (aijfact.c:558)<br>
            ==7368==    by 0x5406B83: MatLUFactorNumeric (matrix.c:3031)<br>
            ==7368==    by 0x609F317: PCSetUp_ILU(_p_PC*) (ilu.c:176)<br>
            ==7368==    by 0x6192D4F: PCSetUp (precon.c:923)<br>
            ==7368==    by 0x62EAE56: KSPSetUp (itfunc.c:381)<br>
            ==7368==    by 0x60190BB:
            PCSetUpOnBlocks_BJacobi_Singleblock(_p_PC*)<br>
            (bjacobi.c:621)<br>
            ==7368==    by 0x619352C: PCSetUpOnBlocks (precon.c:954)<br>
            ==7368==    by 0x62E8F0A: KSPSetUpOnBlocks (itfunc.c:213)<br>
            ==7368==    by 0x62ECCB1: KSPSolve (itfunc.c:613)<br>
            ==7368==    by 0x10FCDD: Elastic::innerstep(double) (in<br>
            /home/telemin/repos/pfire_petsc/bin/pfire)<br>
            ==7368==<br>
            ==7368== Conditional jump or move depends on uninitialised
            value(s)<br>
            ==7368==    at 0x58894EE: PetscAbsScalar(double)
            (petscmath.h:389)<br>
            ==7368==    by 0x5889528: PetscIsNanScalar(double)
            (petscmath.h:674)<br>
            ==7368==    by 0x588A784: MatPivotCheck_none(_p_Mat*,
            _p_Mat*,<br>
            MatFactorInfo const*, FactorShiftCtx*, int) (matimpl.h:704)<br>
            ==7368==    by 0x588AD6E: MatPivotCheck(_p_Mat*, _p_Mat*,
            MatFactorInfo<br>
            const*, FactorShiftCtx*, int) (matimpl.h:727)<br>
            ==7368==    by 0x589177D: MatLUFactorNumeric_SeqAIJ
            (aijfact.c:558)<br>
            ==7368==    by 0x5406B83: MatLUFactorNumeric (matrix.c:3031)<br>
            ==7368==    by 0x609F317: PCSetUp_ILU(_p_PC*) (ilu.c:176)<br>
            ==7368==    by 0x6192D4F: PCSetUp (precon.c:923)<br>
            ==7368==    by 0x62EAE56: KSPSetUp (itfunc.c:381)<br>
            ==7368==    by 0x60190BB:
            PCSetUpOnBlocks_BJacobi_Singleblock(_p_PC*)<br>
            (bjacobi.c:621)<br>
            ==7368==    by 0x619352C: PCSetUpOnBlocks (precon.c:954)<br>
            ==7368==    by 0x62E8F0A: KSPSetUpOnBlocks (itfunc.c:213)<br>
            ==7368==<br>
            ==7368== Conditional jump or move depends on uninitialised
            value(s)<br>
            ==7368==    at 0x4FDACE3: std::isnan(double) (cmath:627)<br>
            ==7368==    by 0x4FDAC8D: PetscIsNanReal (mathinf.c:92)<br>
            ==7368==    by 0x588952D: PetscIsNanScalar(double)
            (petscmath.h:674)<br>
            ==7368==    by 0x588A784: MatPivotCheck_none(_p_Mat*,
            _p_Mat*,<br>
            MatFactorInfo const*, FactorShiftCtx*, int) (matimpl.h:704)<br>
            ==7368==    by 0x588AD6E: MatPivotCheck(_p_Mat*, _p_Mat*,
            MatFactorInfo<br>
            const*, FactorShiftCtx*, int) (matimpl.h:727)<br>
            ==7368==    by 0x589177D: MatLUFactorNumeric_SeqAIJ
            (aijfact.c:558)<br>
            ==7368==    by 0x5406B83: MatLUFactorNumeric (matrix.c:3031)<br>
            ==7368==    by 0x609F317: PCSetUp_ILU(_p_PC*) (ilu.c:176)<br>
            ==7368==    by 0x6192D4F: PCSetUp (precon.c:923)<br>
            ==7368==    by 0x62EAE56: KSPSetUp (itfunc.c:381)<br>
            ==7368==    by 0x60190BB:
            PCSetUpOnBlocks_BJacobi_Singleblock(_p_PC*)<br>
            (bjacobi.c:621)<br>
            ==7368==    by 0x619352C: PCSetUpOnBlocks (precon.c:954)<br>
            <br>
            -- <br>
            Phil Tooley<br>
            Research Software Engineering<br>
            University of Sheffield<br>
            <br>
          </blockquote>
        </div>
        <br clear="all">
        <div><br>
        </div>
        -- <br>
        <div dir="ltr" class="gmail_signature"
          data-smartmail="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>
    <pre class="moz-signature" cols="72">-- 
Phil Tooley
Research Software Engineering
University of Sheffield</pre>
  </body>
</html>