<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    OK, but:<br>
    1. I don't understand what's the use case for MatCopy.<br>
    2. I think it's not good that I can't do the thing without
    reallocations though I have an apriori information where the new
    nonzeros will lie.<br>
    3. Documentation of MatAssemblyBegin/End should definitely contain
    the information about the zero filter.<br>
    <br>
    But OK, 2. is not a problem in my case :-)<br>
    Thank you,<br>
    Vaclav<br>
    <br>
    <br>
    On 03/02/2012 12:18 AM, Matthew Knepley wrote:
    <blockquote
cite="mid:CAMYG4G=6Z6C=6GoXhxAFgVWdFrAnuQcT4gbcQ7VeC-EaqiskBA@mail.gmail.com"
      type="cite">On Thu, Mar 1, 2012 at 5:14 PM, Vaclav Hapla <span
        dir="ltr"><<a moz-do-not-send="true"
          href="mailto:vaclav.hapla@vsb.cz">vaclav.hapla@vsb.cz</a>></span>
      wrote:<br>
      <div class="gmail_quote">
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div bgcolor="#ffffff" text="#000000"> This is what I used
            before for a long time until now when I updated PETSc and it
            started to complain "New nonzero caused a malloc!" when I
            wanted to add </div>
        </blockquote>
        <div><br>
        </div>
        <div>You can turn off this message using MatSetOption(). We put
          it there so people know when allocation is being done since it</div>
        <div>can be slow.</div>
        <div><br>
        </div>
        <div>  Thanks,</div>
        <div><br>
        </div>
        <div>    Matt</div>
        <div> </div>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div bgcolor="#ffffff" text="#000000">some new nonzero outside
            of the original nnz-pattern. MatDuplicate is always
            retaining the pattern, isn't it?<br>
            Vaclav<br>
            <br>
            On 03/02/2012 12:06 AM, Matthew Knepley wrote:
            <blockquote type="cite">On Thu, Mar 1, 2012 at 5:03 PM,
              Vaclav Hapla <span dir="ltr"><<a
                  moz-do-not-send="true"
                  href="mailto:vaclav.hapla@vsb.cz" target="_blank">vaclav.hapla@vsb.cz</a>></span>
              wrote:<br>
              <div class="gmail_quote">
                <blockquote class="gmail_quote" style="margin: 0pt 0pt
                  0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204);
                  padding-left: 1ex;"> Dear PETSc team,<br>
                  why I am not able to do this:<br>
                  <br>
                  ...<br>
                  MatCreate(PETSC_COMM_SELF, &Kreg);<br>
                  MatSetSizes(Kreg,m,n,m,n);<br>
                  MatSetType(Kreg, MATSEQAIJ);<br>
                  MatSeqAIJSetPreallocation(Kreg,0,nnz);<br>
                  MatAssemblyBegin(Kreg, MAT_FINAL_ASSEMBLY);<br>
                  MatAssemblyEnd(   Kreg, MAT_FINAL_ASSEMBLY);<br>
                  PetscFree(nnz);<br>
                  {<br>
                     PetscInt nz_Kreg;<br>
                     MatGetRow(Kreg, 0, &nz_Kreg, PETSC_IGNORE,
                  PETSC_IGNORE);<br>
                     PetscPrintf(PETSC_COMM_SELF, "nnz %d  Kreg %d\n",
                  nnz[0], nz_Kreg);  // prints nnz 11  Kreg 0 !!!<br>
                  }<br>
                  MatCopy(K_loc, Kreg, DIFFERENT_NONZERO_PATTERN);
                  //fails: New nonzero at (0,0) caused a malloc!<br>
                </blockquote>
                <div><br>
                </div>
                <div>I think you want</div>
                <div><br>
                </div>
                <div><a moz-do-not-send="true"
href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatDuplicate.html"
                    target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatDuplicate.html</a></div>
                <div><br>
                </div>
                <div>which does it in one line.</div>
                <div><br>
                </div>
                <div>   Matt</div>
                <div> </div>
                <blockquote class="gmail_quote" style="margin: 0pt 0pt
                  0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204);
                  padding-left: 1ex;"> <br>
                  PETSc complains about new nonzero - not surprisingly
                  because MatAssemblyBegin/End filters zeros as I
                  understand.<br>
                  But when I comment out MatAssemblyBegin/End, MatCopy
                  complains that it is only for assembled matrices.<br>
                  <br>
                  I think that to call MatSetValues on all allocated
                  nonzeros just to make them survive
                  MatAssemblyBegin/End or to replace MatCopy call by
                  loop over raw array is both quite awkward.<br>
                  Maybe one should be able to turn the filter in
                  MatAssemblyBegin/End off. Or is there any other way
                  out?<br>
                  <br>
                  BTW, what I need is to make a copy Kreg of given
                  matrix K_loc but with few additional preallocated
                  positions which are filled later. Is there some other
                  convenient solution?<br>
                  <br>
                  Cheers,<br>
                  Vaclav Hapla<br>
                </blockquote>
              </div>
              <br>
              <br clear="all">
              <span class="HOEnZb"><font color="#888888">
                  <div><br>
                  </div>
                  -- <br>
                  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<br>
                </font></span></blockquote>
            <span class="HOEnZb"><font color="#888888"> <br>
                <br>
                <div>-- <br>
                  <p style="font-size: 11pt; font-family:
                    Verdana,sans-serif;"> Vaclav Hapla<br>
                    Research assistant<br>
                    <a moz-do-not-send="true"
                      href="http://spomech.vsb.cz/" target="_blank">SPOMECH
                      project</a><br>
                    <a moz-do-not-send="true" href="http://www.it4i.eu/"
                      target="_blank">Centre of Excellence
                      IT4Innovations</a> </p>
                  <p style="font-size: 11pt; font-family:
                    Verdana,sans-serif;"> tel.: <a
                      moz-do-not-send="true"
                      href="tel:%28%2B420%29%2059%20732%206291"
                      value="+420597326291" target="_blank">(+420) 59
                      732 6291</a><br>
                    VSB-Technical University of Ostrava<br>
                    17.listopadu 15/2172<br>
                    708 33 Ostrava-Poruba<br>
                    Czech Republic<br>
                  </p>
                </div>
              </font></span></div>
        </blockquote>
      </div>
      <br>
      <br clear="all">
      <div><br>
      </div>
      -- <br>
      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<br>
    </blockquote>
    <br>
    <br>
    <div class="moz-signature">-- <br>
      <p style="font-size: 11pt; font-family: Verdana,sans-serif;">
        Vaclav Hapla<br>
        Research assistant<br>
        <a href="http://spomech.vsb.cz/">SPOMECH project</a><br>
        <a href="http://www.it4i.eu/">Centre of Excellence
          IT4Innovations</a>
      </p>
      <p style="font-size: 11pt; font-family: Verdana,sans-serif;">
        tel.: (+420) 59 732 6291<br>
        VSB-Technical University of Ostrava<br>
        17.listopadu 15/2172<br>
        708 33 Ostrava-Poruba<br>
        Czech Republic<br>
      </p>
    </div>
  </body>
</html>