[petsc-dev] [petsc-users] matrix-matrix addition

Jed Brown jed at 59A2.org
Mon Sep 27 16:33:26 CDT 2010


On Mon, Sep 27, 2010 at 23:28, Shri <abhyshr at mcs.anl.gov> wrote:
>      I've modified MatAXPY_SeqAIJ as follows when DIFFERENT_NONZERO_STRUCTURE flag is true (i) create a new matrix and do preallocation for it. For determining the number of nonzeros per row in the new matrix, i've used the number of nonzeros in the original two matrices. This is the piece of code which computes the nnz per row in the new matrix
>  for(i = 0;i < m;i++) {
>    nzx = xi[i+1] - xi[i]; nzy = yi[i+1] - yi[i];
>    if (nzx > nzy) nnz[i] = nzy + (nzx - nzy);
>    else nnz[i] = nzx + (nzy - nzx);
>  }

What's this supposed to do?  You might as well write

  nnz[i] = PetscMax(nzx,nzy);

But this is not correct because each matrix may have disjoint or
overlapping patterns.  You have to loop through the column indices
(which are sorted) and count the number of unique entries.

Jed



More information about the petsc-dev mailing list