# MatAssemblyEnd
Completes assembling the matrix.  This routine should be called after `MatAssemblyBegin()`. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatAssemblyEnd(Mat mat, MatAssemblyType type)
```
Collective on Mat


## Input Parameters

- ***mat -*** the matrix
- ***type -*** type of assembly, either `MAT_FLUSH_ASSEMBLY` or `MAT_FINAL_ASSEMBLY`



## Options Database Keys

- ***-mat_view ::ascii_info -*** Prints info on matrix at conclusion of `MatEndAssembly()`
- ***-mat_view ::ascii_info_detail -*** Prints more detailed info
- ***-mat_view -*** Prints matrix in ASCII format
- ***-mat_view ::ascii_matlab -*** Prints matrix in Matlab format
- ***-mat_view draw -*** draws nonzero structure of matrix, using `MatView()` and `PetscDrawOpenX()`.
- ***-display <name> -*** Sets display name (default is host)
- ***-draw_pause <sec> -*** Sets number of seconds to pause after display
- ***-mat_view socket -*** Sends matrix to socket, can be accessed from Matlab (See [Using MATLAB with PETSc](ch_matlab))
- ***-viewer_socket_machine <machine> -*** Machine to use for socket
- ***-viewer_socket_port <port> -*** Port number to use for socket
- ***-mat_view binary:filename[:append] -*** Save matrix to file in binary format





## See Also
 `Mat`, `MatAssemblyBegin()`, `MatSetValues()`, `PetscDrawOpenX()`, `PetscDrawCreate()`, `MatView()`, `MatAssembled()`, `PetscViewerSocketOpen()`

## Level
beginner

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

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex12.c.html">src/mat/tutorials/ex12.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex15.c.html">src/mat/tutorials/ex15.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex16.c.html">src/mat/tutorials/ex16.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex17.c.html">src/mat/tutorials/ex17.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex17f.F90.html">src/mat/tutorials/ex17f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex18.c.html">src/mat/tutorials/ex18.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex2.c.html">src/mat/tutorials/ex2.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex3.c.html">src/mat/tutorials/ex3.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex4.c.html">src/mat/tutorials/ex4.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex4f.F90.html">src/mat/tutorials/ex4f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex5cu.cu.html">src/mat/tutorials/ex5cu.cu.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/da/hypre/mhyp.c.html#MatAssemblyEnd_HYPREStruct">MatAssemblyEnd_HYPREStruct in src/dm/impls/da/hypre/mhyp.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/da/hypre/mhyp.c.html#MatAssemblyEnd_HYPRESStruct">MatAssemblyEnd_HYPRESStruct in src/dm/impls/da/hypre/mhyp.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/adj/mpi/mpiadj.c.html#MatAssemblyEnd_MPIAdj">MatAssemblyEnd_MPIAdj in src/mat/impls/adj/mpi/mpiadj.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/crl/mcrl.c.html#MatAssemblyEnd_MPIAIJCRL">MatAssemblyEnd_MPIAIJCRL in src/mat/impls/aij/mpi/crl/mcrl.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/kokkos/mpiaijkok.kokkos.cxx.html#MatAssemblyEnd_MPIAIJKokkos">MatAssemblyEnd_MPIAIJKokkos in src/mat/impls/aij/mpi/kokkos/mpiaijkok.kokkos.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatAssemblyEnd_MPIAIJ">MatAssemblyEnd_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu.html#MatAssemblyEnd_MPIAIJCUSPARSE">MatAssemblyEnd_MPIAIJCUSPARSE in src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpihipsparse/mpiaijhipsparse.hip.c.html#MatAssemblyEnd_MPIAIJHIPSPARSE">MatAssemblyEnd_MPIAIJHIPSPARSE in src/mat/impls/aij/mpi/mpihipsparse/mpiaijhipsparse.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiviennacl/mpiaijviennacl.cxx.html#MatAssemblyEnd_MPIAIJViennaCL">MatAssemblyEnd_MPIAIJViennaCL in src/mat/impls/aij/mpi/mpiviennacl/mpiaijviennacl.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aij.c.html#MatAssemblyEnd_SeqAIJ">MatAssemblyEnd_SeqAIJ in src/mat/impls/aij/seq/aij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aijmkl/aijmkl.c.html#MatAssemblyEnd_SeqAIJMKL">MatAssemblyEnd_SeqAIJMKL in src/mat/impls/aij/seq/aijmkl/aijmkl.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aijperm/aijperm.c.html#MatAssemblyEnd_SeqAIJPERM">MatAssemblyEnd_SeqAIJPERM in src/mat/impls/aij/seq/aijperm/aijperm.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aijsell/aijsell.c.html#MatAssemblyEnd_SeqAIJSELL">MatAssemblyEnd_SeqAIJSELL in src/mat/impls/aij/seq/aijsell/aijsell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/crl/crl.c.html#MatAssemblyEnd_SeqAIJCRL">MatAssemblyEnd_SeqAIJCRL in src/mat/impls/aij/seq/crl/crl.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/kokkos/aijkok.kokkos.cxx.html#MatAssemblyEnd_SeqAIJKokkos">MatAssemblyEnd_SeqAIJKokkos in src/mat/impls/aij/seq/kokkos/aijkok.kokkos.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu.html#MatAssemblyEnd_SeqAIJCUSPARSE">MatAssemblyEnd_SeqAIJCUSPARSE in src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/seqhipsparse/aijhipsparse.hip.c.html#MatAssemblyEnd_SeqAIJHIPSPARSE">MatAssemblyEnd_SeqAIJHIPSPARSE in src/mat/impls/aij/seq/seqhipsparse/aijhipsparse.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx.html#MatAssemblyEnd_SeqAIJViennaCL">MatAssemblyEnd_SeqAIJViennaCL in src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/mpi/mpibaij.c.html#MatAssemblyEnd_MPIBAIJ">MatAssemblyEnd_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#MatAssemblyEnd_SeqBAIJ">MatAssemblyEnd_SeqBAIJ in src/mat/impls/baij/seq/baij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/seq/baijmkl/baijmkl.c.html#MatAssemblyEnd_SeqBAIJMKL">MatAssemblyEnd_SeqBAIJMKL in src/mat/impls/baij/seq/baijmkl/baijmkl.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/blockmat/seq/blockmat.c.html#MatAssemblyEnd_BlockMat">MatAssemblyEnd_BlockMat in src/mat/impls/blockmat/seq/blockmat.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/cdiagonal/cdiagonal.c.html#MatAssemblyEnd_ConstantDiagonal">MatAssemblyEnd_ConstantDiagonal in src/mat/impls/cdiagonal/cdiagonal.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/composite/mcomposite.c.html#MatAssemblyEnd_Composite">MatAssemblyEnd_Composite in src/mat/impls/composite/mcomposite.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/mpi/mpidense.c.html#MatAssemblyEnd_MPIDense">MatAssemblyEnd_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#MatAssemblyEnd_SeqDense">MatAssemblyEnd_SeqDense in src/mat/impls/dense/seq/dense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/elemental/matelem.cxx.html#MatAssemblyEnd_Elemental">MatAssemblyEnd_Elemental in src/mat/impls/elemental/matelem.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/h2opus/cuda/math2opus.cu.html#MatAssemblyEnd_H2OPUS">MatAssemblyEnd_H2OPUS in src/mat/impls/h2opus/cuda/math2opus.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/htool/htool.cxx.html#MatAssemblyEnd_Htool">MatAssemblyEnd_Htool in src/mat/impls/htool/htool.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/hypre/mhypre.c.html#MatAssemblyEnd_HYPRE">MatAssemblyEnd_HYPRE in src/mat/impls/hypre/mhypre.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/is/matis.c.html#MatAssemblyEnd_IS">MatAssemblyEnd_IS in src/mat/impls/is/matis.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/mffd/mffd.c.html#MatAssemblyEnd_MFFD">MatAssemblyEnd_MFFD in src/mat/impls/mffd/mffd.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/nest/matnest.c.html#MatAssemblyEnd_Nest">MatAssemblyEnd_Nest in src/mat/impls/nest/matnest.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/preallocator/matpreallocator.c.html#MatAssemblyEnd_Preallocator">MatAssemblyEnd_Preallocator in src/mat/impls/preallocator/matpreallocator.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/mpi/mpisbaij.c.html#MatAssemblyEnd_MPISBAIJ">MatAssemblyEnd_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#MatAssemblyEnd_SeqSBAIJ">MatAssemblyEnd_SeqSBAIJ in src/mat/impls/sbaij/seq/sbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/scalapack/matscalapack.c.html#MatAssemblyEnd_ScaLAPACK">MatAssemblyEnd_ScaLAPACK in src/mat/impls/scalapack/matscalapack.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/mpi/mpisell.c.html#MatAssemblyEnd_MPISELL">MatAssemblyEnd_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#MatAssemblyEnd_SeqSELL">MatAssemblyEnd_SeqSELL in src/mat/impls/sell/seq/sell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/shell/shell.c.html#MatAssemblyEnd_Shell">MatAssemblyEnd_Shell in src/mat/impls/shell/shell.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)  
