<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<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>
<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>
<p><br>
</p>
<p>Patrick<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 8/22/22 10:03, Zhang, Hong wrote:<br>
</div>
<blockquote type="cite"
cite="mid:SA1PR09MB8607667B9B068ADE59ACC19588719@SA1PR09MB8607.namprd09.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
<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="LPlnkOWALinkPreview" moz-do-not-send="true"
class="moz-txt-link-freetext">https://petsc.org/release/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation</a></div>
<div class="_Entity _EType_OWALinkPreview _EId_OWALinkPreview
_EReadonly_1">
<div
id="LPBorder_GTaHR0cHM6Ly9wZXRzYy5vcmcvcmVsZWFzZS9kb2NzL21hbnVhbHBhZ2VzL01hdC9NYXRNUElBSUpTZXRQcmVhbGxvY2F0aW9uLmh0bWwjTWF0TVBJQUlKU2V0UHJlYWxsb2NhdGlvbg.."
class="LPBorder175907" style="width: 100%; margin-top: 16px;
margin-bottom: 16px; position: relative; max-width: 800px;
min-width: 424px;">
<table id="LPContainer175907" 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="LPTitle175907" 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 target="_blank" id="LPUrlAnchor175907"
href="https://petsc.org/release/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation"
style="text-decoration: none; color:
var(--themePrimary);" moz-do-not-send="true">MatMPIAIJSetPreallocation
- PETSc</a></div>
<div id="LPDescription175907" style="font-size: 14px;
max-height: 100px; color: rgb(102, 102, 102);
font-family: wf_segoe-ui_normal, "Segoe
UI", "Segoe WP", Tahoma, Arial,
sans-serif; margin-bottom: 12px; margin-right: 8px;
overflow: hidden;">
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="LPMetadata175907" style="font-size: 14px;
font-weight: 400; color: rgb(166, 166, 166);
font-family: wf_segoe-ui_normal, "Segoe
UI", "Segoe WP", Tahoma, Arial,
sans-serif;">
petsc.org</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%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
face="Calibri, sans-serif" color="#000000"><b>From:</b>
petsc-users <a class="moz-txt-link-rfc2396E" href="mailto:petsc-users-bounces@mcs.anl.gov"><petsc-users-bounces@mcs.anl.gov></a> on behalf
of Patrick Alken <a class="moz-txt-link-rfc2396E" href="mailto:patrick.alken@geomag.info"><patrick.alken@geomag.info></a><br>
<b>Sent:</b> Monday, August 22, 2022 10:56 AM<br>
<b>To:</b> petsc-users <a class="moz-txt-link-rfc2396E" href="mailto:petsc-users@mcs.anl.gov"><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 class="BodyFragment"><font size="2"><span
style="font-size:11pt;">
<div class="PlainText">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>
</body>
</html>