:orphan:
# MatRestoreRow
Frees any temporary space allocated by `MatGetRow()`. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatRestoreRow(Mat mat, PetscInt row, PetscInt *ncols, const PetscInt *cols[], const PetscScalar *vals[])
```
Not Collective


## Input Parameters

- ***mat -*** the matrix
- ***row -*** the row to get
- ***ncols -*** the number of nonzeros
- ***cols -*** the columns of the nonzeros
- ***vals -*** if nonzero the column values





## Notes
This routine should be called after you have finished examining the entries.

This routine zeros out `ncols`, `cols`, and `vals`. This is to prevent accidental
us of the array after it has been restored. If you pass `NULL`, it will
not zero the pointers.  Use of `cols` or `vals` after `MatRestoreRow()` is invalid.


## Fortran Notes
The calling sequence is
```none
   MatRestoreRow(matrix,row,ncols,cols,values,ierr)
      Mat     matrix (input)
      integer row    (input)
      integer ncols  (output)
      integer cols(maxcols) (output)
      double precision (or double complex) values(maxcols) output
```

Where maxcols >= maximum nonzeros in any row of the matrix.

In Fortran `MatRestoreRow()` MUST be called after `MatGetRow()`
before another call to `MatGetRow()` can be made.


## See Also
 [](ch_matrices), `Mat`, `MatGetRow()`

## Level
advanced

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

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex19.c.html">src/ksp/ksp/tutorials/ex19.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex59.c.html">src/ksp/ksp/tutorials/ex59.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex12.c.html">src/mat/tutorials/ex12.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex16.c.html">src/mat/tutorials/ex16.c</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/adj/mpi/mpiadj.c.html#MatRestoreRow_MPIAdj">MatRestoreRow_MPIAdj in src/mat/impls/adj/mpi/mpiadj.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatRestoreRow_MPIAIJ">MatRestoreRow_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#MatRestoreRow_SeqAIJ">MatRestoreRow_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#MatRestoreRow_MPIBAIJ">MatRestoreRow_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#MatRestoreRow_SeqBAIJ">MatRestoreRow_SeqBAIJ in src/mat/impls/baij/seq/baij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/cdiagonal/cdiagonal.c.html#MatRestoreRow_ConstantDiagonal">MatRestoreRow_ConstantDiagonal in src/mat/impls/cdiagonal/cdiagonal.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/mpi/mpidense.c.html#MatRestoreRow_MPIDense">MatRestoreRow_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#MatRestoreRow_SeqDense">MatRestoreRow_SeqDense in src/mat/impls/dense/seq/dense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/htool/htool.cxx.html#MatRestoreRow_Htool">MatRestoreRow_Htool in src/mat/impls/htool/htool.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/hypre/mhypre.c.html#MatRestoreRow_HYPRE">MatRestoreRow_HYPRE in src/mat/impls/hypre/mhypre.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/kaij/kaij.c.html#MatRestoreRow_SeqKAIJ">MatRestoreRow_SeqKAIJ in src/mat/impls/kaij/kaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/kaij/kaij.c.html#MatRestoreRow_MPIKAIJ">MatRestoreRow_MPIKAIJ in src/mat/impls/kaij/kaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/mpi/mpisbaij.c.html#MatRestoreRow_MPISBAIJ">MatRestoreRow_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#MatRestoreRow_SeqSBAIJ">MatRestoreRow_SeqSBAIJ in src/mat/impls/sbaij/seq/sbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/seq/sell.c.html#MatRestoreRow_SeqSELL">MatRestoreRow_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](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
