<div dir="ltr">So, seems like a fix we should make at this point is to make MatPreallocator explicitly single use, throwing an error if MatPreallocatorPreallocate is called a second time. (Still open for further debate as to what to do in general but this quick patch to release to replace the crash with an error message seems justified in any case).<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Fr., 4. Feb. 2022 um 02:02 Uhr schrieb Jed Brown <<a href="mailto:jed@jedbrown.org">jed@jedbrown.org</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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.<br>
<br>
Marius Buerkle <<a href="mailto:mbuerkle@web.de" target="_blank">mbuerkle@web.de</a>> writes:<br>
<br>
> 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.<br>
><br>
> Thanks for the feedback.<br>
><br>
>> Gesendet: Donnerstag, den 03.02.2022 um 03:09 Uhr<br>
>> Von: "Jed Brown" <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>><br>
>> An: "Marius Buerkle" <<a href="mailto:mbuerkle@web.de" target="_blank">mbuerkle@web.de</a>>, "Patrick Sanan" <<a href="mailto:patrick.sanan@gmail.com" target="_blank">patrick.sanan@gmail.com</a>><br>
>> Cc: "PETSc users list" <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>>, petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>><br>
>> Betreff: Re: Aw: Re: [petsc-dev] [petsc-users] MatPreallocatorPreallocate segfault with PETSC 3.16<br>
>><br>
>> Marius Buerkle <<a href="mailto:mbuerkle@web.de" target="_blank">mbuerkle@web.de</a>> writes:<br>
>><br>
>> > 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.<br>
>> > Anyway it works with MatDuplicate for now.<br>
>><br>
>> 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.<br>
</blockquote></div>