[petsc-users] matrix-matrix addition

Barry Smith bsmith at mcs.anl.gov
Mon Sep 27 12:01:07 CDT 2010


On Sep 27, 2010, at 11:39 AM, Jed Brown wrote:

> On Mon, Sep 27, 2010 at 18:36, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>   You need to merge the two arrays, don't you? I was suggested the linked list to do the merge, but I am sure you are correct there are other better ways to do merges.
> 
> Why do you need to actually merge them?  You need to count the number
> in the diagonal and off-diagonal part, but then aren't you going to
> build a matrix using MatSetValues(...,ADD_VALUES)?  You could of
> course merge them in a temporary buffer (trivial as long as it has
> been allocated large enough) to get one MatSetValues for the whole
> row, instead of one for the row from A and another for the row from B.
> The rows are both sorted, so they can be merged into a buffer in a
> single pass.
> 
> Jed

   Jed, 

(1) this has nothing to do with parallel matrices and diagonal and off diagonal parts

(2) this is about preallocation, not setting the values.

If you do not merge the column indices from A and B but simply count them all you will get over allocation, at worst a factor of two, though usually it would just be a little.

   Barry



More information about the petsc-users mailing list