# VecView
Views a vector object. 
## Synopsis
```
#include "petscvec.h"   
PetscErrorCode VecView(Vec vec, PetscViewer viewer)
```
Collective


## Input Parameters

- ***vec -*** the vector
- ***viewer -*** an optional visualization context





## Notes
The available visualization contexts include

- ***`PETSC_VIEWER_STDOUT_SELF` -*** for sequential vectors
- ***`PETSC_VIEWER_STDOUT_WORLD` -*** for parallel vectors created on `PETSC_COMM_WORLD`
- ***`PETSC_VIEWER_STDOUT`_(comm) -*** for parallel vectors created on MPI communicator comm


You can change the format the vector is printed using the
option `PetscViewerPushFormat()`.

The user can open alternative viewers with

- ***`PetscViewerASCIIOpen()` -*** Outputs vector to a specified file
- ***`PetscViewerBinaryOpen()` -*** Outputs vector in binary to a
specified file; corresponding input uses `VecLoad()`
- ***`PetscViewerDrawOpen()` -*** Outputs vector to an X window display
- ***`PetscViewerSocketOpen()` -*** Outputs vector to Socket viewer
- ***`PetscViewerHDF5Open()` -*** Outputs vector to HDF5 file 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 vector contents
- ***`PETSC_VIEWER_ASCII_MATLAB` -*** prints vector contents in MATLAB format
- ***`PETSC_VIEWER_ASCII_INDEX` -*** prints vector contents, including indices of vector elements
- ***`PETSC_VIEWER_ASCII_COMMON` -*** prints vector contents, using a
format common among all vector types


You can pass any number of vector objects, or other PETSc objects to the same viewer.

In the debugger you can do call `VecView`(v,0) to display the vector. (The same holds for any PETSc object viewer).


## Notes for binary viewer
If you pass multiple vectors to a binary viewer you can read them back in in the same order
with `VecLoad()`.

If the blocksize of the vector is greater than one then you must provide a unique prefix to
the vector with `PetscObjectSetOptionsPrefix`((`PetscObject`)vec,"uniqueprefix"); BEFORE calling `VecView()` on the
vector to be stored and then set that same unique prefix on the vector that you pass to `VecLoad()`. The blocksize
information is stored in an ASCII file with the same name as the binary file plus a ".info" appended to the
filename. If you copy the binary file, make sure you copy the associated .info file with it.

See the manual page for `VecLoad()` on the exact format the binary viewer stores
the values in the file.


## Notes for HDF5 Viewer
The name of the `Vec` (given with `PetscObjectSetName()` is the name that is used
for the object in the HDF5 file. If you wish to store the same Vec into multiple
datasets in the same file (typically with different values), you must change its
name each time before calling the `VecView()`. To load the same vector,
the name of the Vec object passed to `VecLoad()` must be the same.

If the block size of the vector is greater than 1 then it is used as the first dimension in the HDF5 array.
If the function `PetscViewerHDF5SetBaseDimension2()`is called then even if the block size is one it will
be used as the first dimension in the HDF5 array (that is the HDF5 array will always be two dimensional)
See also `PetscViewerHDF5SetTimestep()` which adds an additional complication to reading and writing `Vec`
with the HDF5 viewer.


## See Also
 [](chapter_vectors), `Vec`, `PetscViewerASCIIOpen()`, `PetscViewerDrawOpen()`, `PetscDrawLGCreate()`,
`PetscViewerSocketOpen()`, `PetscViewerBinaryOpen()`, `VecLoad()`, `PetscViewerCreate()`,
`PetscRealView()`, `PetscScalarView()`, `PetscIntView()`, `PetscViewerHDF5SetTimestep()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/interface/vector.c.html#VecView">src/vec/vec/interface/vector.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex10.c.html">src/vec/vec/tutorials/ex10.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex12.c.html">src/vec/vec/tutorials/ex12.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex12f.F90.html">src/vec/vec/tutorials/ex12f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex14f.F90.html">src/vec/vec/tutorials/ex14f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex15.c.html">src/vec/vec/tutorials/ex15.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex16.c.html">src/vec/vec/tutorials/ex16.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex16f.F90.html">src/vec/vec/tutorials/ex16f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex19.c.html">src/vec/vec/tutorials/ex19.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex2.c.html">src/vec/vec/tutorials/ex2.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex21f90.F90.html">src/vec/vec/tutorials/ex21f90.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex2f.F90.html">src/vec/vec/tutorials/ex2f.F90.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/composite/pack.c.html#VecView_DMComposite">VecView_DMComposite in src/dm/impls/composite/pack.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/forest/p4est/pforest.h.html#VecView_pforest">VecView_pforest in src/dm/impls/forest/p4est/pforest.h</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/network/networkcreate.c.html#VecView_Network">VecView_Network in src/dm/impls/network/networkcreate.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/plex.c.html#VecView_Plex">VecView_Plex in src/dm/impls/plex/plex.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/swarm/swarm.c.html#VecView_Swarm">VecView_Swarm in src/dm/impls/swarm/swarm.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/mpi/pdvec.c.html#VecView_MPI">VecView_MPI in src/vec/vec/impls/mpi/pdvec.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/nest/vecnest.c.html#VecView_Nest">VecView_Nest in src/vec/vec/impls/nest/vecnest.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/bvec2.c.html#VecView_Seq">VecView_Seq in src/vec/vec/impls/seq/bvec2.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/vec/vec/interface/vector.c)


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