Yes, it looks like a bug since no one tested this situation.
MatSetPreallocationCOO() is pretty heavy memory-wise. It essentially keeps a copy of all the coo_i, coo_j indices within the Mat as well as the usual matrix information. So in your scenario, you will have two copies of all this stuff; lots of memory. Is this really what you need? > On Apr 26, 2023, at 4:07 PM, Maxime Bouyges <[email protected]> wrote: > > Dear PETSc developers, > > I am trying to use the MatSetValuesCOO function (very appropriate and > performant for my case) but I am encountering a problem when I use it on a > Mat obtained with MatDuplicate. It seems that the non-zero pattern is > preserved by MatDuplicate, but not the "COO information". Here are the few > steps to reproduce the problem: > MatCreate(comm, A) > MatSetUp(A) > MatSetPreallocationCOO(A, ncoo, coo_i, coo_j) > MatSetValuesCOO(A, coo_v, INSERT_VALUES) # -> works ok > MatDuplicate(A, MAT_DO_NOT_COPY_VALUES, B) > MatSetValuesCOO(B, coo_v, INSERT_VALUES) # -> seg-fault > > Is this an expected behaviour? Of course if I call again > MatSetPreallocationCOO on the duplicated matrix it's ok but the performance > is lost in my case. Is there a way to fix it? Thank you in advance. > > Best regards, > > Maxime Bouyges >
