# MatView
display information about a matrix in a variety ways 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatView(Mat mat, PetscViewer viewer)
```
Collective


## Input Parameters

- ***mat -*** the matrix
- ***viewer -*** visualization context



## Notes
The available visualization contexts include

- ***`PETSC_VIEWER_STDOUT_SELF` -*** for sequential matrices
- ***`PETSC_VIEWER_STDOUT_WORLD` -*** for parallel matrices created on `PETSC_COMM_WORLD`
- ***`PETSC_VIEWER_STDOUT_`(comm) -*** for matrices created on MPI communicator comm
- ***`PETSC_VIEWER_DRAW_WORLD` -*** graphical display of nonzero structure


The user can open alternative visualization contexts with

- ***`PetscViewerASCIIOpen()` -*** Outputs matrix to a specified file
- ***`PetscViewerBinaryOpen()` -*** Outputs matrix in binary to a
specified file; corresponding input uses MatLoad()
- ***`PetscViewerDrawOpen()` -*** Outputs nonzero matrix structure to
an X window display
- ***`PetscViewerSocketOpen()` -*** Outputs matrix to Socket viewer.
Currently only the sequential dense and AIJ
matrix types support the Socket viewer.


The user can call `PetscViewerPushFormat()` to specify the output
format of ASCII printed objects (when using `PETSC_VIEWER_STDOUT_SELF`,
`PETSC_VIEWER_STDOUT_WORLD` and `PetscViewerASCIIOpen()`).  Available formats include

- ***`PETSC_VIEWER_DEFAULT` -*** default, prints matrix contents
- ***`PETSC_VIEWER_ASCII_MATLAB` -*** prints matrix contents in Matlab format
- ***`PETSC_VIEWER_ASCII_DENSE` -*** prints entire matrix including zeros
- ***`PETSC_VIEWER_ASCII_COMMON` -*** prints matrix contents, using a sparse
format common among all matrix types
- ***`PETSC_VIEWER_ASCII_IMPL` -*** prints matrix contents, using an implementation-specific
format (which is in many cases the same as the default)
- ***`PETSC_VIEWER_ASCII_INFO` -*** prints basic information about the matrix
size and structure (not the matrix entries)
- ***`PETSC_VIEWER_ASCII_INFO_DETAIL` -*** prints more detailed information about
the matrix structure



## Options Database Keys

- ***-mat_view ::ascii_info -*** Prints info on matrix at conclusion of `MatAssemblyEnd()`
- ***-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 -*** PetscDraws 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 Users-Manual: ch_matlab for details)
- ***-viewer_socket_machine <machine> -*** 
- ***-viewer_socket_port <port> -*** 
- ***-mat_view binary -*** save matrix to file in binary format
- ***-viewer_binary_filename <name> -*** 





## Notes
The ASCII viewers are only recommended for small matrices on at most a moderate number of processes,
the program will seemingly hang and take hours for larger matrices, for larger matrices one should use the binary format.

In the debugger you can do "call MatView(mat,0)" to display the matrix. (The same holds for any PETSc object viewer).

See the manual page for `MatLoad()` for the exact format of the binary file when the binary
viewer is used.

See share/petsc/matlab/PetscBinaryRead.m for a Matlab code that can read in the binary file when the binary
viewer is used and lib/petsc/bin/PetscBinaryIO.py for loading them into Python.

One can use '-mat_view draw -draw_pause -1' to pause the graphical display of matrix nonzero structure,
and then use the following mouse functions.
```none
  left mouse: zoom in
  middle mouse: zoom out
  right mouse: continue with the simulation
```



## See Also
 `Mat`, `PetscViewerPushFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerDrawOpen()`, `PetscViewer`,
`PetscViewerSocketOpen()`, `PetscViewerBinaryOpen()`, `MatLoad()`, `MatViewFromOptions()`

## Level
beginner

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

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex6.c.html">src/vec/vec/tutorials/ex6.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex11.c.html">src/mat/tutorials/ex11.c.html</A><BR>
<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/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/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/ex8.c.html">src/mat/tutorials/ex8.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex14.c.html">src/dm/tutorials/ex14.c.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/adj/mpi/mpiadj.c.html#MatView_MPIAdj">MatView_MPIAdj in src/mat/impls/adj/mpi/mpiadj.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/clique/clique.cxx.html#MatView_SparseElemental">MatView_SparseElemental in src/mat/impls/aij/mpi/clique/clique.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatView_MPIAIJ">MatView_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mumps/mumps.c.html#MatView_MUMPS">MatView_MUMPS in src/mat/impls/aij/mpi/mumps/mumps.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/pastix/pastix.c.html#MatView_PaStiX">MatView_PaStiX in src/mat/impls/aij/mpi/pastix/pastix.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/strumpack/strumpack.c.html#MatView_STRUMPACK">MatView_STRUMPACK in src/mat/impls/aij/mpi/strumpack/strumpack.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aij.c.html#MatView_SeqAIJ">MatView_SeqAIJ in src/mat/impls/aij/seq/aij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/klu/klu.c.html#MatView_KLU">MatView_KLU in src/mat/impls/aij/seq/klu/klu.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/matlab/aijmatlab.c.html#MatView_Matlab">MatView_Matlab in src/mat/impls/aij/seq/matlab/aijmatlab.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/superlu/superlu.c.html#MatView_SuperLU">MatView_SuperLU in src/mat/impls/aij/seq/superlu/superlu.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/umfpack/umfpack.c.html#MatView_UMFPACK">MatView_UMFPACK in src/mat/impls/aij/seq/umfpack/umfpack.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/mpi/mpibaij.c.html#MatView_MPIBAIJ">MatView_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#MatView_SeqBAIJ">MatView_SeqBAIJ in src/mat/impls/baij/seq/baij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/blockmat/seq/blockmat.c.html#MatView_BlockMat">MatView_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#MatView_ConstantDiagonal">MatView_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#MatView_MPIDense">MatView_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#MatView_SeqDense">MatView_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#MatView_Elemental">MatView_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#MatView_H2OPUS">MatView_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#MatView_Htool">MatView_Htool in src/mat/impls/htool/htool.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/hypre/mhypre.c.html#MatView_HYPRE">MatView_HYPRE in src/mat/impls/hypre/mhypre.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/is/matis.c.html#MatView_IS">MatView_IS in src/mat/impls/is/matis.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/kaij/kaij.c.html#MatView_KAIJ">MatView_KAIJ in src/mat/impls/kaij/kaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/maij/maij.c.html#MatView_SeqMAIJ">MatView_SeqMAIJ in src/mat/impls/maij/maij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/maij/maij.c.html#MatView_MPIMAIJ">MatView_MPIMAIJ in src/mat/impls/maij/maij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/mffd/mffd.c.html#MatView_MFFD">MatView_MFFD in src/mat/impls/mffd/mffd.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/nest/matnest.c.html#MatView_Nest">MatView_Nest in src/mat/impls/nest/matnest.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/preallocator/matpreallocator.c.html#MatView_Preallocator">MatView_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#MatView_MPISBAIJ">MatView_MPISBAIJ in src/mat/impls/sbaij/mpi/mpisbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/seq/cholmod/sbaijcholmod.c.html#MatView_CHOLMOD">MatView_CHOLMOD in src/mat/impls/sbaij/seq/cholmod/sbaijcholmod.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/seq/sbaij.c.html#MatView_SeqSBAIJ">MatView_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#MatView_ScaLAPACK">MatView_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#MatView_MPISELL">MatView_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#MatView_SeqSELL">MatView_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)  
