# KSPCreateVecs
Gets a number of work vectors suitably sized for the operator in the `KSP` 
## Synopsis
```
#include "petscksp.h" 
PetscErrorCode KSPCreateVecs(KSP ksp, PetscInt rightn, Vec **right, PetscInt leftn, Vec **left)
```
Collective on ksp


## Input Parameters

- ***ksp  -*** iterative context
- ***rightn  -*** number of right work vectors
- ***leftn   -*** number of left work vectors to allocate



## Output Parameters

- ***right -*** the array of vectors created
- ***left -*** the array of left vectors





## Notes
The right vector has as many elements as the matrix has columns. The left
vector has as many elements as the matrix has rows.

The vectors are new vectors that are not owned by the `KSP`, they should be destroyed with calls to `VecDestroyVecs()` when no longer needed.


## Developers Note
First tries to duplicate the rhs and solution vectors of the `KSP`, if they do not exist tries to get them from the matrix, if
that does not exist tries to get them from the `DM` (if it is provided).


## See Also
 [](chapter_ksp), `MatCreateVecs()`, `VecDestroyVecs()`, `KSPSetWorkVecs()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/interface/iterativ.c.html#KSPCreateVecs">src/ksp/ksp/interface/iterativ.c</A>


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


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