# MatDenseGetSubMatrix
Gives access to a block of rows and columns of a dense matrix, represented as a Mat. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatDenseGetSubMatrix(Mat A, PetscInt rbegin, PetscInt rend, PetscInt cbegin, PetscInt cend, Mat *v)
```
Collective


## Input Parameters

- ***mat -*** the Mat object
- ***rbegin -*** the first global row index in the block (if PETSC_DECIDE, is 0)
- ***rend -*** the global row index past the last one in the block (if PETSC_DECIDE, is M)
- ***cbegin -*** the first global column index in the block (if PETSC_DECIDE, is 0)
- ***cend -*** the global column index past the last one in the block (if PETSC_DECIDE, is N)



## Output Parameter

- ***v -*** the matrix



## Notes
The matrix is owned by PETSc. Users need to call MatDenseRestoreSubMatrix() when the matrix is no longer needed.

The output matrix is not redistributed by PETSc, so depending on the values of rbegin and rend, some processes may have no local rows.




## See Also
 `MATDENSE`, `MATDENSECUDA`, `MATDENSEHIP`, `MatDenseGetColumnVec()`, `MatDenseRestoreColumnVec()`, `MatDenseRestoreSubMatrix()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/seq/dense.c.html#MatDenseGetSubMatrix">src/mat/impls/dense/seq/dense.c</A>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/mpi/mpidense.c.html#MatDenseGetSubMatrix_MPIDense">MatDenseGetSubMatrix_MPIDense in src/mat/impls/dense/mpi/mpidense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/seq/cuda/densecuda.cu.html#MatDenseGetSubMatrix_SeqDenseCUDA">MatDenseGetSubMatrix_SeqDenseCUDA in src/mat/impls/dense/seq/cuda/densecuda.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/seq/dense.c.html#MatDenseGetSubMatrix_SeqDense">MatDenseGetSubMatrix_SeqDense in src/mat/impls/dense/seq/dense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/seq/hip/densehip.hip.c.html#MatDenseGetSubMatrix_SeqDenseHIP">MatDenseGetSubMatrix_SeqDenseHIP in src/mat/impls/dense/seq/hip/densehip.hip.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/impls/dense/seq/dense.c)


[Index of all Mat routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
