# VecLoad
Loads a vector that has been stored in binary or HDF5 format with `VecView()`. 
## Synopsis
```
#include "petscvec.h"   
PetscErrorCode VecLoad(Vec vec, PetscViewer viewer)
```
Collective


## Input Parameters

- ***vec -*** the newly loaded vector, this needs to have been created with `VecCreate()` or
some related function before a call to VecLoad().
- ***viewer -*** binary file viewer, obtained from PetscViewerBinaryOpen() or
HDF5 file viewer, obtained from PetscViewerHDF5Open()





## Notes
Defaults to the standard Seq or MPI Vec, if you want some other type of `Vec` call `VecSetFromOptions()`
before calling this.

The input file must contain the full global vector, as
written by the routine `VecView()`.

If the type or size of vec is not set before a call to `VecLoad()`, PETSc
sets the type and the local and global sizes. If type and/or
sizes are already set, then the same are used.

If using the binary viewer and 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.

If using HDF5, you must assign the Vec the same name as was used in the Vec
that was stored in the file using `PetscObjectSetName(). Otherwise you will
get the error message: "Cannot H5DOpen2() with `Vec` name NAMEOFOBJECT".

If the HDF5 file contains a two dimensional array the first dimension is treated as the block size
in loading the vector. Hence, for example, using MATLAB notation h5create('vector.dat','/Test_Vec',[27 1]);
will load a vector of size 27 and block size 27 thus resulting in all 27 entries being on the first process of
vectors communicator and the rest of the processes having zero entries


## Notes for advanced users when using the binary viewer
Most users should not need to know the details of the binary storage
format, since `VecLoad()` and `VecView()` completely hide these details.
But for anyone who's interested, the standard binary vector storage
format is
```none
     PetscInt    VEC_FILE_CLASSID
     PetscInt    number of rows
     PetscScalar *values of all entries
```


In addition, PETSc automatically uses byte swapping to work on all machines; the files
are written ALWAYS using big-endian ordering. On small-endian machines the numbers
are converted to the small-endian format when they are read in from the file.
See PetscBinaryRead() and PetscBinaryWrite() to see how this may be done.


## See Also
 [](chapter_vectors), `Vec`, `PetscViewerBinaryOpen()`, `VecView()`, `MatLoad()`, `VecLoad()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/interface/vector.c.html#VecLoad">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/ex19.c.html">src/vec/vec/tutorials/ex19.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex42.c.html">src/vec/vec/tutorials/ex42.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex42a.c.html">src/vec/vec/tutorials/ex42a.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex5.c.html">src/vec/vec/tutorials/ex5.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex5f.F90.html">src/vec/vec/tutorials/ex5f.F90.html</A><BR>
<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/ex12.c.html">src/mat/tutorials/ex12.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex10.c.html">src/dm/tutorials/ex10.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex15.c.html">src/dm/tutorials/ex15.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex9.c.html">src/dm/tutorials/ex9.c.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/forest/p4est/pforest.h.html#VecLoad_pforest">VecLoad_pforest in src/dm/impls/forest/p4est/pforest.h</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/plex.c.html#VecLoad_Plex">VecLoad_Plex in src/dm/impls/plex/plex.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)  
