<div dir="ltr">First of all, thank you so much for the detailed answers!<div>That clears up most of my confusion. Just to clarify let me make sure I understand everything:</div><div>1. So it seems that your advice is just to call the MatXAIJSetPreallocation() routine (rather than make separate calls to other preallocation routines such as MatSeqAIJPreallcation() and MatMPIAIJPreallcation())? This will preallocate for Seq and MPI matrices (among other types) and the decision will be made at runtime?</div><div>2. So the old way was just to call MatSeqAIJPreallcation() and MatMPIAIJPreallcation()? I had thought that if you called the sequential version for a parallel matrix or vice versa that the program would crash. It seems that instead nothing happens, so by calling both you were covered in either case. Is this correct? Essentially, one would always execute and the other would do nothing?</div><div>3. If the dnnzu and onnzu arrays for the upper triangular parts seem unnecessary for me I can just call the MatXAIJSetPreallocation() routine with those values set to 'NULL'? I'm really just looking for a blend of the MatSeqAIJPreallcation() and MatMPIAIJPreallcation() routines so it seems that I only need dnnz and onnz arrays.</div><div>4. If we ignore the dnnzu and onnzu upper triangular parameters, then the MatXAIJSetPreallocation() routine has the same parameters as the MatMPIAIJSetPreallocation() routine without the option to give constant integer values for diagonal and off-diagonal parts of the matrix so it seems clear to me how this routine would work for a parallel matrix when the upper triangular parameters are NULL. If the matrix is sequential then does MPIXAIJSetPreallocation() just ignore the onnz parameter and just use the dnnz parameter as the sole argument for determining preallocation? </div><div><br></div><div>Thanks again for all the help. I think I understand well enough to use this routine now. The questions above are mostly just to clarify and double-check that I understood your previous responses correctly.</div><div><br></div><div>Sam</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Feb 5, 2022 at 10:12 AM Mark Adams <<a href="mailto:mfadams@lbl.gov">mfadams@lbl.gov</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 dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Feb 5, 2022 at 10:36 AM 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-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Fri, Feb 4, 2022 at 11:47 PM Samuel Estes <<a href="mailto:samuelestes91@gmail.com" target="_blank">samuelestes91@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><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 dir="ltr">Hi,<div><br></div><div>I have a very basic question about matrix preallocation. I am trying to use the MatCreate(), MatSetFromOptions(), MatXXXXSetPreallocation() paradigm. I thought that I should use the MatXAIJSetPreallocation() routine since the code may be run with a SeqAIJ or MPIAIJ matrix but I do not understand all of the inputs required for the MatXAIJSetPreallocation routine. In particular, the dnnzu and onnzu variables don't quite make sense to me. Can these be NULL? I was basically just hoping for a routine that would preallocate for either a sequential or parallel matrix depending on what was given at runtime. This routine seems to be what I want but I don't understand it very well and the documentation hasn't helped me to figure it out.</div></div></blockquote><div><br></div><div>The example for this is here</div><div><br></div><div> <a href="https://petsc.org/main/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation" target="_blank">https://petsc.org/main/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation</a></div><div><br></div><div>Maybe we should copy it to the XAIJ page as well. Does this help explain the arguments?</div><div> </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 dir="ltr"><div>A related followup question: Is it good practice to use this function or should I just use the other routines like MatSeqAIJSetPreallocation() and MatMPIAIJSetPreallocation()? </div><div><br></div><div>And finally my last question: if I were to use the MatSeqAIJSetPreallocation()/MatMPIAIJSetPreallocation() routines for preallocating memory, is it common to just call MatGetType() then call the appropriate routine depending on whether or not the matrix is parallel or not? I ask because when I have tested these routines out, it seems that MatSeqAIJSetPreallocation() works even for parallel matrices which is a bit confusing. I'm assuming that it just sets the diagonal part of the matrix?</div></div></blockquote><div><br></div><div>No, it definitely will not preallocate in parallel, so something else is happening.</div></div></div></blockquote><div><br></div><div>With only MatSeqAIJSetPreallocation in parallel it would not do any preallocation, in which case it would fall back to dynamic allocation. I'm guessing that is what is happening and it will be very slow.</div><div> <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 dir="ltr"><div class="gmail_quote"><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-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I hope that my questions were clear. Let me know if they need clarification and thanks in advance for the help!</div><div><br></div><div>Sam</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></div>
</blockquote></div>