[petsc-users] adding mat rows

Barry Smith bsmith at mcs.anl.gov
Thu Nov 19 12:55:40 CST 2015


> On Nov 19, 2015, at 11:25 AM, Carles Bona <carlesbona at gmail.com> wrote:
> 
> Dear all,
> 
> I would like to add some of my equations before I modify them.

   Please explain what you mean by this. Algebraically exactly what do you want to do?


> I haven't found any high level function that would allow me to add rows of a matrix (I am working with a parallel BAIJ). Is there any nice way of doing this?
> 
> I have tried with MatGetRow/MatRestoreRow, but I am struggling a bit to retain the cols and vals, as only one processor can call MatGetRow but if only that processor tries to allocate memory then one gets a segmentation fault. I guess I should allocate enough memory on all processors... 
> 
> If I refrain from storing the cols and vals I need to call MatSetValues before returning the pointer, with a subsequent call to assemblybegin/end for each row, which slows down the code.
> 
> The other option would be to forget about these row additions after the matrix has been filled and try to fill it while taking into account these row additions at the same time. I guess I need to be constantly checking for indices then.
> 
> So, which option (not necessarily mentioned here) would you reccomend?
> 
> Thanks a lot,
> 
> Carles



More information about the petsc-users mailing list