<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 4, 2022 at 11:47 PM Samuel Estes <<a href="mailto:samuelestes91@gmail.com">samuelestes91@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">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? </div></div></blockquote><div><br></div><div>Yes. The integer is ignored if you provide the array. Just make sure that the integer is an upper bound on the number of non-zeros in any row. If not, MatSetValues can be very slow. Otherwise, the performance hit is not bad.</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>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. </div></div></blockquote><div><br></div><div>That is what the "X" is for. It is basically syntactic sugar to call the right version of preallocate (seq, mpi, blocked versions, hypre, etc.)</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>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>Sorry,</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><br></div><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></blockquote><div><br></div><div>Yes this is the way to go. </div><div>TL;DR</div><div>Before we had a sparse matrix type explosion with GPUs, you could call both the MPI and Seq versions and be fine. You could call the blocked versions I suppose to be safe.</div><div>But now there are several GPU/device enabled matrix types and "X" is convenient.</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><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? </div></div></blockquote><div><br></div><div>You could do that but no need. As I said, the old way was to call both.</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>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>There is probably a default. It should work w/o any of these calls, but performance would suffer if the default (10 maybe) is too small for you.</div><div> </div><div>Mark</div><div><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><br></div><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></div>