MatPreallocator stores "the nonzero structure" in a hash table so it can be 
easily updated. A normal Mat stores it in a compressed (CSR) format that is 
expensive to update.

Marius Buerkle <[email protected]> writes:

> Ok. I did not know that. I was under the impression that MatPreallocator does 
> actually not allocate the nonzeros and just stores the nonzero structure. But 
> if this is not the case then of course I just duplicate the matrix.
>
> Thanks for the feedback.
>
>> Gesendet: Donnerstag, den 03.02.2022 um 03:09 Uhr
>> Von: "Jed Brown" <[email protected]>
>> An: "Marius Buerkle" <[email protected]>, "Patrick Sanan" 
>> <[email protected]>
>> Cc: "PETSc users list" <[email protected]>, petsc-dev 
>> <[email protected]>
>> Betreff: Re: Aw: Re: [petsc-dev] [petsc-users] MatPreallocatorPreallocate 
>> segfault with PETSC 3.16
>>
>> Marius Buerkle <[email protected]> writes:
>>
>> > Thanks for they reply. Yes the example works, this is how I was doing it 
>> > before. But the matrix is rather big and i need a matrix with the same 
>> > structure at various points in my code. So it was convenient to create the 
>> > matrix with preallocate, destroy it after using it to free the memory and 
>> > creating it again later with the same preallocate.
>> > Anyway it works with MatDuplicate for now.
>>
>> I think it should take *less* memory to destroy the preallocator and 
>> duplicate the actual matrix than to destroy the matrix and persist the 
>> preallocator. If that is not the case (or close enough), we can make it so.

Reply via email to