<div dir="ltr">Ok, thanks. <br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 11, 2021 at 1:38 PM Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Mon, Jan 11, 2021 at 4:32 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</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 dir="ltr">A follow up question: if I call preallocation, is there any performance difference between <div><pre width="80" style="color:rgb(0,0,0)"><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValues.html#MatSetValues" target="_blank">MatSetValues</a>(mat,1,&I,1,&J,&v,<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES" target="_blank">INSERT_VALUES</a>); // insert value one by one</pre><pre width="80" style="color:rgb(0,0,0)">vs</pre><pre width="80" style="color:rgb(0,0,0)"><pre><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValues.html#MatSetValues" target="_blank">MatSetValues</a>(<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/Mat.html#Mat" target="_blank">Mat</a> mat,<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt" target="_blank">PetscInt</a> m,const <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt" target="_blank">PetscInt</a> idxm[],<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt" target="_blank">PetscInt</a> n,const <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt" target="_blank">PetscInt</a> idxn[],const <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar" target="_blank">PetscScalar</a> v[],<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/InsertMode.html#InsertMode" target="_blank">InsertMode</a> addv) // insert multiple values</pre><pre>My input is triple arrays</pre><pre>vector<int> r;</pre><pre>vector<int> c;</pre><pre>vector<double> a;</pre><pre>where r/c are not sorted by rows/cols. I don't want to waste memory/time to create idxm/idxn unless there is a performance penalty.</pre></pre></div></div></blockquote><div><br></div><div>It is cheaper to insert many values than sequences of single values. However, allocating memory is much much more expensive. As with most performance questions, there is no substitute for experiments.</div><div><br></div><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 dir="ltr"><div><pre width="80" style="color:rgb(0,0,0)"><pre>Thanks,</pre><pre>Sam</pre>



</pre><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 11, 2021 at 12:27 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thanks! <br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 11, 2021 at 12:25 PM Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Mon, Jan 11, 2021 at 3:00 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</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 dir="ltr">Dear PETSc Dev Team,<div>   The documentation recommends calling 

both of the above preallocation routines for simplicity. Do we waste memory by calling both?</div></div></blockquote><div><br></div><div>No. Only one will function, depending on the matrix type.</div><div><br></div><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 dir="ltr"><div>Thanks,</div><div>Sam</div><div><a name="m_-3265480383013867168_m_45597025335856553_m_5523074487952674709_m_-182855358411706255_m_-2499245619606312561_MATAIJ" style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><h1>MATAIJ</h1></a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"></span><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MATAIJ.html#MATAIJ" style="font-family:"Times New Roman";font-size:medium" target="_blank">MATAIJ</a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> = "aij" - A matrix type to be used for sparse matrices. This matrix type is identical to </span><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MATSEQAIJ.html#MATSEQAIJ" style="font-family:"Times New Roman";font-size:medium" target="_blank">MATSEQAIJ</a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> when constructed with a single process communicator, and </span><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MATMPIAIJ.html#MATMPIAIJ" style="font-family:"Times New Roman";font-size:medium" target="_blank">MATMPIAIJ</a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> otherwise. As a result, for single process communicators, </span><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSeqAIJSetPreallocation.html#MatSeqAIJSetPreallocation" style="font-family:"Times New Roman";font-size:medium" target="_blank">MatSeqAIJSetPreallocation</a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> is supported, and similarly </span><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation" style="font-family:"Times New Roman";font-size:medium" target="_blank">MatMPIAIJSetPreallocation</a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">() is supported for communicators controlling multiple processes. It is recommended that you call both of the above preallocation routines for simplicity.</span>    <br></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><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>
</blockquote></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><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>
</blockquote></div>