[petsc-users] Matrix preallocation
Matthew Knepley
knepley at gmail.com
Sat Feb 5 09:35:46 CST 2022
On Fri, Feb 4, 2022 at 11:47 PM Samuel Estes <samuelestes91 at gmail.com>
wrote:
> Hi,
>
> 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.
>
The example for this is here
https://petsc.org/main/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation
Maybe we should copy it to the XAIJ page as well. Does this help explain
the arguments?
> A related followup question: Is it good practice to use this function or
> should I just use the other routines like MatSeqAIJSetPreallocation() and
> MatMPIAIJSetPreallocation()?
>
> 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?
>
No, it definitely will not preallocate in parallel, so something else is
happening.
Thanks,
Matt
> I hope that my questions were clear. Let me know if they need
> clarification and thanks in advance for the help!
>
> Sam
>
--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220205/35194b71/attachment.html>
More information about the petsc-users
mailing list