<div><br></div><div><br><div class="gmail_quote"><div dir="ltr">On Thu 21. May 2020 at 12:17, Yang Bo (Asst Prof) <<a href="mailto:yang.bo@ntu.edu.sg">yang.bo@ntu.edu.sg</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div style="word-wrap:break-word;line-break:after-white-space">
Hi Dave,
<div><br>
</div>
<div>Yes it is parallel so the preallocation calls are not lowered by the allocation.</div>
<div><br>
</div>
<div>I am trying to use MatXAIJSetPreallocation, but not sure how, since the following link does not give an example:</div>
<div><br>
</div>
<div><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatXAIJSetPreallocation.html" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatXAIJSetPreallocation.html</a></div>
<div><br>
</div>
<div>If I have the following matrix:</div>
<div><br>
</div>
<div>0 1 2 0 </div>
<div>1 0 0 0 </div>
<div>2 0 1 3</div>
<div>0 0 3 2 </div>
<div><br>
</div>
<div>How should I put in the parameters of MatXAIJSetPreallocation?</div></div></blockquote><div dir="auto"><br></div><div dir="auto">Please read this page to understand the info required</div><div dir="auto"><br></div><div dir="auto"><div><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html</a></div><br></div><div dir="auto"><br></div><div dir="auto">Compute everything as described above and give the results to MatXAIJSetPreallocation(). MatXAIJSetPreallocation() is just a helper function to hide all the implementation specific setters.</div><div dir="auto"><br></div><div dir="auto">Thanks</div><div dir="auto">Dave</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div></div>
<div><br>
</div>
<div>Thanks!</div>
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
<div>Yang Bo</div></div><div style="word-wrap:break-word;line-break:after-white-space">
<div><br>
<div><br>
<blockquote type="cite">
<div>On 21 May 2020, at 5:42 PM, Dave May <<a href="mailto:dave.mayhem23@gmail.com" target="_blank">dave.mayhem23@gmail.com</a>> wrote:</div>
<br>
<div><br>
<br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div dir="ltr">On Thu 21. May 2020 at 10:49, Yang Bo (Asst Prof) <<a href="mailto:yang.bo@ntu.edu.sg" target="_blank">yang.bo@ntu.edu.sg</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div style="word-wrap:break-word;line-break:after-white-space">Hi Dave,
<div><br>
</div>
<div>Thank you very much for your reply. That is indeed the problem. I have been working with matrices in Slepc but I don’t really understand it. I tried to preallocate but it still does not work.<span> </span></div>
</div>
</blockquote>
<div dir="auto"><br>
</div>
<div dir="auto">Meaning the number of reported mallocs is still non-zero?</div>
<div dir="auto">Is the number reported with you preallocation calls lower than what you originally saw?</div>
<div dir="auto"><br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div style="word-wrap:break-word;line-break:after-white-space">
<div>If you look at my code below:</div>
<div><br>
</div>
<div>
<div>ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);</div>
<div>ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,h_dim,h_dim);<span style="white-space:pre-wrap">
</span>                     // h_dim is the dimension of the square matrix A</div>
<div>ierr = MatSetFromOptions(A);CHKERRQ(ierr);</div>
<div>ierr = MatSetUp(A);CHKERRQ(ierr);</div>
<div>ierr = MatGetOwnershipRange(A,&Istart,&Iend);CHKERRQ(ierr);</div>
<div><br>
</div>
<div>MatSeqAIJSetPreallocation(A,0,nnz);                                      <span> </span><span style="white-space:pre-wrap"></span>// I try to preallocate here, where nnz is the array containing the number
 of non-zero entries each row</div>
<div><br>
</div>
<div>for (int i=0;i<row.size();i++) {</div>
<div><span style="white-space:pre-wrap"></span>MatSetValue(A,row[i],column[i],h[i],INSERT_VALUES);</div>
<div>}</div>
</div>
<div><br>
</div>
<div>I am not sure what other information I need to give for the pre-allocation…</div>
<div></div>
</div>
</blockquote>
<div dir="auto"><br>
</div>
<div dir="auto">This looks fine. However MatSeqAIJSetPreallocation() has no effect if the Mat type is not SEQAIJ.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Are you running in parallel? If yes then the Mat type will be MATMPIAIJ and you either have to call the MPI specific preallocator or use the generic one I pointed you too.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Thanks</div>
<div dir="auto">Dave</div>
<div dir="auto"><br>
</div>
<div dir="auto"><br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div style="word-wrap:break-word;line-break:after-white-space">
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
<div>Yang Bo</div>
<div><br>
</div>
<div><br>
<div><br>
<blockquote type="cite">
<div>On 21 May 2020, at 4:08 PM, Dave May <<a href="mailto:dave.mayhem23@gmail.com" target="_blank">dave.mayhem23@gmail.com</a>> wrote:</div>
<br>
<div><b style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">-info
 | grep malloc</b></div>
</blockquote>
</div>
<br>
</div>
</div>
<div style="word-wrap:break-word;line-break:after-white-space">
<hr>
<p style="font-size:10pt;color:rgb(128,128,128);font-family:Arial">
CONFIDENTIALITY: This email is intended solely for the person(s) named and may be confidential and/or privileged. If you are not the intended recipient, please delete it, notify us and do not copy, use, or disclose its contents.<span> </span><br>
Towards a sustainable earth: Print only when necessary. Thank you.<span> </span></p>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>

</blockquote></div></div>