<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div>  Sam,<div class=""><br class=""></div><div class="">    In the master development branch of PETSc Stefano has started to add support for directly providing matrix entries in "coordinate" form (COO) (the triple arrays you use). </div><div class=""><br class=""></div><div class="">    It supports MatSetPreallocationCOO() and MatSetValuesCOO(). </div><div class=""><br class=""></div><div class="">    Currently Stefano has optimized it for use with GPUs but it will also work for CPUs and we can add optimizations in the future.</div><div class=""><br class=""></div><div class="">    You might consider using these in your code instead of managing the setting of each value individually.</div><div class=""><br class=""></div><div class="">    Barry</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 11, 2021, at 3:45 PM, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" class="">sam.guo@cd-adapco.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Ok, thanks. <br class=""></div><br class=""><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" class="">knepley@gmail.com</a>> wrote:<br class=""></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" class=""><div dir="ltr" class="">On Mon, Jan 11, 2021 at 4:32 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank" class="">sam.guo@cd-adapco.com</a>> wrote:<br class=""></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" class="">A follow up question: if I call preallocation, is there any performance difference between <div class=""><pre width="80" style="" class=""><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValues.html#MatSetValues" target="_blank" class="">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" class="">INSERT_VALUES</a>); // insert value one by one</pre><pre width="80" style="" class="">vs</pre><pre width="80" style="" class=""><pre class=""><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValues.html#MatSetValues" target="_blank" class="">MatSetValues</a>(<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/Mat.html#Mat" target="_blank" class="">Mat</a> mat,<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt" target="_blank" class="">PetscInt</a> m,const <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt" target="_blank" class="">PetscInt</a> idxm[],<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt" target="_blank" class="">PetscInt</a> n,const <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt" target="_blank" class="">PetscInt</a> idxn[],const <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar" target="_blank" class="">PetscScalar</a> v[],<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/InsertMode.html#InsertMode" target="_blank" class="">InsertMode</a> addv) // insert multiple values</pre><pre class="">My input is triple arrays</pre><pre class="">vector<int> r;</pre><pre class="">vector<int> c;</pre><pre class="">vector<double> a;</pre><pre class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">  Thanks,</div><div class=""><br class=""></div><div class="">     Matt</div><div class=""> </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" class=""><div class=""><pre width="80" style="" class=""><pre class="">Thanks,</pre><pre class="">Sam</pre>



</pre><div class=""><br class=""></div></div></div><br class=""><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" class="">sam.guo@cd-adapco.com</a>> wrote:<br class=""></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" class="">Thanks! <br class=""></div><br class=""><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" class="">knepley@gmail.com</a>> wrote:<br class=""></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" class=""><div dir="ltr" class="">On Mon, Jan 11, 2021 at 3:00 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank" class="">sam.guo@cd-adapco.com</a>> wrote:<br class=""></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" class="">Dear PETSc Dev Team,<div class="">   The documentation recommends calling 

both of the above preallocation routines for simplicity. Do we waste memory by calling both?</div></div></blockquote><div class=""><br class=""></div><div class="">No. Only one will function, depending on the matrix type.</div><div class=""><br class=""></div><div class="">  Thanks,</div><div class=""><br class=""></div><div class="">     Matt</div><div class=""> </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" class=""><div class="">Thanks,</div><div class="">Sam</div><div class=""><a name="m_-3265480383013867168_m_45597025335856553_m_5523074487952674709_m_-182855358411706255_m_-2499245619606312561_MATAIJ" style="font-family: "Times New Roman"; font-size: inherit;" class=""><h1 class="">MATAIJ</h1></a><span style="font-family: "Times New Roman"; font-size: inherit;" class=""></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: inherit;" target="_blank" class="">MATAIJ</a><span style="font-family: "Times New Roman"; font-size: inherit;" class=""> = "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: inherit;" target="_blank" class="">MATSEQAIJ</a><span style="font-family: "Times New Roman"; font-size: inherit;" class=""> 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: inherit;" target="_blank" class="">MATMPIAIJ</a><span style="font-family: "Times New Roman"; font-size: inherit;" class=""> 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: inherit;" target="_blank" class="">MatSeqAIJSetPreallocation</a><span style="font-family: "Times New Roman"; font-size: inherit;" class=""> 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: inherit;" target="_blank" class="">MatMPIAIJSetPreallocation</a><span style="font-family: "Times New Roman"; font-size: inherit;" class="">() is supported for communicators controlling multiple processes. It is recommended that you call both of the above preallocation routines for simplicity.</span>    <br class=""></div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a><br class=""></div></div></div></div></div></div></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a><br class=""></div></div></div></div></div></div></div></div>
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>