<div dir="ltr">There is also the hedge of adding a parameter and API function to control which of these two behaviors is used, and if trying to preallocate twice, throwing an error that instructs the user how to change the behavior, noting that it will increase peak memory usage.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Di., 1. Feb. 2022 um 17:07 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">Stefano Zampini <<a href="mailto:stefano.zampini@gmail.com" target="_blank">stefano.zampini@gmail.com</a>> writes:<br>
<br>
> Il giorno mar 1 feb 2022 alle ore 18:34 Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> ha<br>
> scritto:<br>
><br>
>> Patrick Sanan <<a href="mailto:patrick.sanan@gmail.com" target="_blank">patrick.sanan@gmail.com</a>> writes:<br>
>><br>
>> > Am Di., 1. Feb. 2022 um 16:20 Uhr schrieb Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>>:<br>
>> ><br>
>> >> Patrick Sanan <<a href="mailto:patrick.sanan@gmail.com" target="_blank">patrick.sanan@gmail.com</a>> writes:<br>
>> >><br>
>> >> > Sorry about the delay on this. I can reproduce.<br>
>> >> ><br>
>> >> > This regression appears to be a result of this optimization:<br>
>> >> > <a href="https://gitlab.com/petsc/petsc/-/merge_requests/4273" rel="noreferrer" target="_blank">https://gitlab.com/petsc/petsc/-/merge_requests/4273</a><br>
>> >><br>
>> >> Thanks for tracking this down. Is there a reason to prefer preallocating<br>
>> >> twice<br>
>> >><br>
>> >>    ierr =<br>
>> >> MatPreallocatorPreallocate(preallocator,PETSC_TRUE,A);CHKERRQ(ierr);<br>
>> >>    ierr =<br>
>> >><br>
>> MatPreallocatorPreallocate(preallocator,PETSC_TRUE,A_duplicate);CHKERRQ(ierr);<br>
>> >><br>
>> >> versus using MatDuplicate() or MatConvert()?<br>
>> >><br>
>><br>
><br>
> Jed<br>
><br>
> this is not the point. Suppose you pass around only a preallocator, but do<br>
> not pass around the matrices. Reusing the preallocator should be allowed.<br>
<br>
The current code is not okay (crashing is not okay), but we should decide whether to consume the preallocator or to retain the data structure. Peak memory use is the main reason hash-based allocation hasn't been default and wasn't adopted sooner. Retaining the hash until the preallocator is destroyed increases that peak.<br>
</blockquote></div>