[petsc-users] matrix-matrix addition
Jed Brown
jed at 59A2.org
Mon Sep 27 11:30:03 CDT 2010
On Mon, Sep 27, 2010 at 18:24, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
> We need an efficient MatAXPY() that works well for any combination of nonzero patterns. This is not terribly difficult to write. Basically for each row create a linked list of the nonzeros in it from the first matrix and then merge in the nonzeros from the second matrix for that row, much like in the LU symbolic factorizations. This will give you row counts, then preallocate the correct nonzero matrix and do the MatSetValues() for the first matrix first row then the second matrix first row etc. Finally swap in the new matrix body into the current matrix.
I don't see why you'd need a linked list for this, you have two sorted
arrays (one for each row) and just need to count the number of unique
elements. It's one loop.
Jed
More information about the petsc-users
mailing list