[petsc-users] About matrix assembly
Matthew Knepley
knepley at gmail.com
Mon Dec 5 07:16:31 CST 2022
On Mon, Dec 5, 2022 at 6:48 AM 김성익 <ksi2443 at gmail.com> wrote:
> Hello,
>
> In matrix preallocation procedure, I tried 2 options to preallocate global
> matrix.
> The first is ‘MatSeqAIJSetPreallocation’ and the second is
> ‘MatSetPreallocationCOO’.
>
>
>
> When I adopt the first option “MatSeqAIJSetPreallocation(Mat, nz, nnz)”, I
> just put overestimated nz for getting enough memory space and also getting
> nice performance.
>
> However, It couldn’t run without “MatSetOption(Mat,
> MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);” And also, there are no speed
> up compare with no preallocation case.
>
1. This means your nz was not big enough.
2. I suggest computing the correct length for every row. The easiest way to
do this is to use
https://petsc.org/main/docs/manualpages/Mat/MatPreallocatorPreallocate/
There re instructions on that page. This is how I do it in the library now.
>
>
> When in the second option “MatSetPreallocationCOO(Mat,ncoo,coo_i,coo_j)”,
> I put correct size parameters(ncoo, coo_i, coo_j). However, It couldn’t run
> without “MatSetOption(Mat, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);”
> Regarding this problem, I suspect that it is a problem caused by mapping a
> small-sized local matrix with a different order from the order of coo_i and
> coo_j to the global matrix by using “matsetvalue”. And also, there are no
> speed up compare with no preallocation case.
>
If you cannot run without that flag, it means that you are inserting
different nonzeros then you did with MatSetPreallocationCOO(). You need to
tell
it _exactly_ the same nonzeros as you input with MatSetValues().
Thanks,
Matt
> 1. How can I do proper preallocation procedure?
>
> 2. Why in my cases there are no speed up?
>
>
>
> Thanks,
>
> Hyung Kim
>
--
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/20221205/d5e03e24/attachment.html>
More information about the petsc-users
mailing list