[petsc-users] Assembling a matrix from submatrices

Jed Brown jedbrown at mcs.anl.gov
Mon Apr 22 10:07:47 CDT 2013

Matthew Knepley <knepley at gmail.com> writes:

> On Mon, Apr 22, 2013 at 9:14 AM, Jan Essert <netz at essert.name> wrote:
>> Dear list,
>> I would like to construct a large, sparse matrix M out of four submatrices.
>> (A B)
>> (C D)
>> These submatrices are obtained as results of MatMatMult multiplications of
>> other sparse matrices.
>> I have tried the following procedure for all four submatrices (here only
>> for A)
>> Mat A;
>> MatGetLocalSubMatrix(M, rows1, cols1, MAT_INITIAL_MATRIX, &A);
>> MatRestoreLocalSubMatrix(M, rows1, cols1, &A);
> MAT_INITIAL_MATRIX creates the matrix. You need MAT_RESUE_MATRIX.

This won't work either because MatGetLocalSubMatrix() does not work that
way and because MAT_REUSE_MATRIX requires that you have already used
that matrix for the given operation.

You can create a MATNEST for the coupled matrix, but if you want it
fully assembled, you'll have to loop over the rows and call
MatSetValues.  We have a partial implementation of MatConvert_Nest_AIJ
that, once completed, will provide a nicer interface for this.

More information about the petsc-users mailing list