<div dir="ltr"><div dir="ltr">On Mon, Aug 22, 2022 at 12:12 PM Patrick Alken <<a href="mailto:patrick.alken@geomag.info">patrick.alken@geomag.info</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>Thank you, I have read that document. I have changed my criteria
      to:</p>
    <p><br>
    </p>
    <p>if (j >= first && (j - first) < m) {</p></div></blockquote><div>As Barry says, this should be</div><div><br></div><div>if ((j >= first) && (j < last)) {</div><div> </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>  /*diagonal*/</p>
    <p>else</p>
    <p>  /*off-diagonal*/</p>
    <p><br>
    </p>
    <p>It seems to be working better. I don't know how to get the c1 and
      c2 columns referred to by the documentation.</p></div></blockquote><div>Thanks</div><div><br></div><div>    Matt</div><div> </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>Patrick<br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
    <div>On 8/22/22 10:03, Zhang, Hong wrote:<br>
    </div>
    <blockquote type="cite">
      
      
      <div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
        See <a href="https://petsc.org/release/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation" id="gmail-m_-7078473661605830769LPlnkOWALinkPreview" target="_blank">https://petsc.org/release/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation</a></div>
      <div>
        <div id="gmail-m_-7078473661605830769LPBorder_GTaHR0cHM6Ly9wZXRzYy5vcmcvcmVsZWFzZS9kb2NzL21hbnVhbHBhZ2VzL01hdC9NYXRNUElBSUpTZXRQcmVhbGxvY2F0aW9uLmh0bWwjTWF0TVBJQUlKU2V0UHJlYWxsb2NhdGlvbg.." style="width:100%;margin-top:16px;margin-bottom:16px;max-width:800px;min-width:424px">
          <table id="gmail-m_-7078473661605830769LPContainer175907" role="presentation" style="padding:12px 36px 12px 12px;width:100%;border-width:1px;border-style:solid;border-color:rgb(200,200,200);border-radius:2px">
            <tbody>
              <tr style="border-spacing:0px" valign="top">
                <td style="width:100%">
                  <div id="gmail-m_-7078473661605830769LPTitle175907" style="font-size:21px;font-weight:300;margin-right:8px;font-family:wf_segoe-ui_light,"Segoe UI Light","Segoe WP Light","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif;margin-bottom:12px">
                    <a id="gmail-m_-7078473661605830769LPUrlAnchor175907" href="https://petsc.org/release/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation" style="text-decoration:none" target="_blank">MatMPIAIJSetPreallocation
                      - PETSc</a></div>
                  <div id="gmail-m_-7078473661605830769LPDescription175907">
                    MatMPIAIJSetPreallocation Preallocates memory for a
                    sparse parallel matrix in AIJ format (the default
                    parallel PETSc format). For good matrix assembly
                    performance the user should preallocate the matrix
                    storage by setting the parameters d_nz (or d_nnz)
                    and o_nz (or o_nnz).</div>
                  <div id="gmail-m_-7078473661605830769LPMetadata175907">
                    <a href="http://petsc.org" target="_blank">petsc.org</a></div>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
        if you use mpiaij matrix.</div>
      <div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
        Hong</div>
      <hr style="display:inline-block;width:98%">
      <div id="gmail-m_-7078473661605830769divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b>
          petsc-users <a href="mailto:petsc-users-bounces@mcs.anl.gov" target="_blank"><petsc-users-bounces@mcs.anl.gov></a> on behalf
          of Patrick Alken <a href="mailto:patrick.alken@geomag.info" target="_blank"><patrick.alken@geomag.info></a><br>
          <b>Sent:</b> Monday, August 22, 2022 10:56 AM<br>
          <b>To:</b> petsc-users <a href="mailto:petsc-users@mcs.anl.gov" target="_blank"><petsc-users@mcs.anl.gov></a><br>
          <b>Subject:</b> [petsc-users] Preallocating a matrix with the
          d_nnz and o_nnz arrays</font>
        <div> </div>
      </div>
      <div><font size="2"><span style="font-size:11pt">
            <div>I am looping through all the non-zero
              elements of my matrix to count the
              <br>
              diagonal and off-diagonal terms in order to pre-allocate
              the matrix. <br>
              However, what is the criteria for knowing if a given
              element is in the <br>
              diagonal portion or off-diagonal portion? It seems that it
              will depend <br>
              on row, column, and also processor. I was doing something
              like this:<br>
              <br>
              MatGetLocalSize(A, &m, &n);<br>
              <br>
              MatGetOwnershipRange(A, &first, &last);<br>
              <br>
              for (i = first; i < last; ++i) {<br>
              <br>
                   for (j = 0; j < N; ++j) {<br>
              <br>
                       if (abs(i - j) < m)<br>
              <br>
                           ++d_nnz[i - first];<br>
              <br>
                       else<br>
              <br>
                           ++o_nnz[i - first];<br>
              <br>
                   }<br>
              <br>
              }<br>
              <br>
              However, the criteria: abs(i - j) < m is not correct. I
              think the <br>
              correct criteria will include the processor number also.
              Does anyone <br>
              know the correct criteria to use?<br>
              <br>
            </div>
          </span></font></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">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>