# MatGetSubMatrix

Gets a single submatrix on the same number of processors as the original matrix.

### Synopsis

    #include "petscmat.h"
    PetscErrorCode  MatGetSubMatrix(Mat mat,IS isrow,IS iscol,PetscInt csize,MatReuse cll,Mat *newmat)

Collective on Mat

### Input Parameters

| mat | - the original matrix
| isrow | - rows this processor should obtain
| iscol | - columns for all processors you wish to keep
| csize | - number of columns "local" to this processor (does nothing for sequential matrices). This should match the result from VecGetLocalSize(x,...) if you plan to use the matrix in a A*x; alternatively, you can use PETSC_DECIDE
| cll | - either MAT_INITIAL_MATRIX or MAT_REUSE_MATRIX

### Output Parameter

newmat -the new submatrix, of the same type as the old

Notes: the iscol argument MUST be the same on each processor. You might be able to create the iscol argument with ISAllGather(). The rows is isrow will be sorted into the same order as the original matrix.

The first time this is called you should use a cll of MAT_INITIAL_MATRIX, the MatGetSubMatrix() routine will create the newmat for you. Any additional calls to this routine with a mat of the same nonzero structure and with a call of MAT_REUSE_MATRIX will reuse the matrix generated the first time. You should call MatDestroy() on newmat when you are finished using it.

### See Also

MatGetSubMatrices(), ISAllGather()

Level:advanced
Location:src/mat/interface/matrix.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages

### Examples

src/ksp/ksp/examples/tutorials/ex10.c.html