[petsc-users] matrix-matrix addition

Barry Smith bsmith at mcs.anl.gov
Mon Sep 27 11:24:42 CDT 2010


  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.

If this is done for SeqAIJ then MPIAIJ simply needs to call this for the two submatrices. Similar beasty can be done for BAIJ. Do you need AIJ or BAIJ?

  Shri,

     Could you please start on this (drop the VI for a couple of days to get this done)? Let me know if you have any questions.

   Thanks

    Barry



On Sep 27, 2010, at 12:56 AM, Boyce Griffith wrote:

> I am trying to compute a matrix A that is of the form:
> 
>   A = B + P^t C P
> 
> using MatPtAP and MatAXPY.  The call to MatAXPY is very slow --- presumably because I haven't allocated the correct nonzero structure.  I can easily determine the nonzero structures of B, C, and P, but I do not think that I can easily compute the nonzero structure of P^t C P (although I can compute its nonzero structure with some difficulty).
> 
> Is it possible to add extra non-zero locations to an existing matrix? Or should I try to extract the nonzero structures of B and P^t C P to pre-allocate A correctly?  (Or am I overlooking some functionality in PETSc that will do most of this for me?)
> 
> A tangentially related question is: is there any way to find out the actual fill (or fill ratio) following a call to MatPtAP?
> 
> Thanks in advance for any suggestions!
> 
> -- Boyce



More information about the petsc-users mailing list