# MatGetValues
Gets a block of local values from a matrix. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatGetValues(Mat mat, PetscInt m, const PetscInt idxm[], PetscInt n, const PetscInt idxn[], PetscScalar v[])
```
Not Collective; can only return values that are owned by the give process


## Input Parameters

- ***mat -*** the matrix
- ***v -*** a logically two-dimensional array for storing the values
- ***m, idxm -*** the number of rows and their global indices
- ***n, idxn -*** the number of columns and their global indices



## Notes
The user must allocate space (m*n `PetscScalar`s) for the values, v.
The values, v, are then returned in a row-oriented format,
analogous to that used by default in `MatSetValues()`.

`MatGetValues()` uses 0-based row and column numbers in
Fortran as well as in C.

`MatGetValues()` requires that the matrix has been assembled
with `MatAssemblyBegin()`/`MatAssemblyEnd()`.  Thus, calls to
`MatSetValues()` and `MatGetValues()` CANNOT be made in succession
without intermediate matrix assembly.

Negative row or column indices will be ignored and those locations in v[] will be
left unchanged.

For the standard row-based matrix formats, idxm[] can only contain rows owned by the requesting MPI rank.
That is, rows with global index greater than or equal to rstart and less than rend where rstart and rend are obtainable
from `MatGetOwnershipRange`(mat,&rstart,&rend).




## See Also
 `Mat`, `MatGetRow()`, `MatCreateSubMatrices()`, `MatSetValues()`, `MatGetOwnershipRange()`, `MatGetValuesLocal()`, `MatGetValue()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/interface/matrix.c.html#MatGetValues">src/mat/interface/matrix.c</A>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatGetValues_MPIAIJ">MatGetValues_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aij.c.html#MatGetValues_SeqAIJ">MatGetValues_SeqAIJ in src/mat/impls/aij/seq/aij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/mpi/mpibaij.c.html#MatGetValues_MPIBAIJ">MatGetValues_MPIBAIJ in src/mat/impls/baij/mpi/mpibaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/seq/baij.c.html#MatGetValues_SeqBAIJ">MatGetValues_SeqBAIJ in src/mat/impls/baij/seq/baij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/mpi/mpidense.c.html#MatGetValues_MPIDense">MatGetValues_MPIDense in src/mat/impls/dense/mpi/mpidense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/seq/dense.c.html#MatGetValues_SeqDense">MatGetValues_SeqDense in src/mat/impls/dense/seq/dense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/hypre/mhypre.c.html#MatGetValues_HYPRE">MatGetValues_HYPRE in src/mat/impls/hypre/mhypre.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/mpi/mpisbaij.c.html#MatGetValues_MPISBAIJ">MatGetValues_MPISBAIJ in src/mat/impls/sbaij/mpi/mpisbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/seq/sbaij.c.html#MatGetValues_SeqSBAIJ">MatGetValues_SeqSBAIJ in src/mat/impls/sbaij/seq/sbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/mpi/mpisell.c.html#MatGetValues_MPISELL">MatGetValues_MPISELL in src/mat/impls/sell/mpi/mpisell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/seq/sell.c.html#MatGetValues_SeqSELL">MatGetValues_SeqSELL in src/mat/impls/sell/seq/sell.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/interface/matrix.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)  
