Assembling a matrix

Barry Smith bsmith at mcs.anl.gov
Tue Dec 8 16:26:50 CST 2009


   Where will the "new" row live? On the last process, why that one?

    Does the matrix A have to be completely assembled before the v is  
computed? Or can the entries of A be computed at the same time as the v?

   PETSc doesn't have code to efficiently dynamically change the size  
of a matrix. Thus generating a new matrix from a given sparse matrix  
plus a new row requires a complete copy of the  starting matrix into  
the new matrix data structure. If you assemble the entire matrix  
together without first generating the smaller matrix A then it is  
easy; just generate the preallocation structure of A with the one  
additional row/column information and call MatSetValues() to put in  
the parts of A and the parts of v.

    Barry

On Dec 8, 2009, at 4:05 PM, Anirban Chatterjee wrote:

> Hi,
>
> I have an nxn matrix A, a column vector v and a scalar c. I want to  
> assemble a matrix B as follows,
> B = [A v;
>       v^T c]
> Can someone tell me the easiest and most efficient way to do this.
>
> --Anirban



More information about the petsc-users mailing list