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); >> MatMatMult(A1, A2, MAT_INITIAL_MATRIX, PETSC_DEFAULT, &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.
