[petsc-users] About matrix assembly
Mark Adams
mfadams at lbl.gov
Mon Dec 5 09:01:50 CST 2022
I don't think you understand COO. Look at the example
https://petsc.org/release/src/mat/tutorials/ex18.c.html
"MatSetPreallocationCOO" is not a great name because you are giving it the
(i,j) indices not just the sizes for memory allocation.
A MatSetPreallocationCOO that is consistent with MatSeqAIJSetPreallocation
would just take one integer: "ncoo" .
MatSetIndicesCOO might be a better name.
Mark
On Mon, Dec 5, 2022 at 8:16 AM Matthew Knepley <knepley at gmail.com> wrote:
> 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/485e0034/attachment-0001.html>
More information about the petsc-users
mailing list