# KSPBuildSolution

Builds the approximate solution in a vector provided. This routine is NOT commonly needed (see KSPSolve()).

### Synopsis

    #include "petscksp.h"
    PetscErrorCode PETSCKSP_DLLEXPORT KSPBuildSolution(KSP ksp,Vec v,Vec *V)

Collective on KSP

### Input Parameter

ctx -iterative context obtained from KSPCreate()

### Output Parameter

Provide exactly one of

| v | - location to stash solution.
| V | - the solution is returned in this location. This vector is created internally. This vector should NOT be destroyed by the user with VecDestroy().

### Notes

This routine can be used in one of two ways

          KSPBuildSolution(ksp,PETSC_NULL,&V);
       or
          KSPBuildSolution(ksp,v,PETSC_NULL);

In the first case an internal vector is allocated to store the solution (the user cannot destroy this vector). In the second case the solution is generated in the vector that the user provides. Note that for certain methods, such as KSPCG, the second case requires a copy of the solution, while in the first case the call is essentially free since it simply returns the vector where the solution already is stored.

### Keywords

KSP, build, solution

### See Also

KSPGetSolution(), KSPBuildResidual()

Level:advanced
Location:src/ksp/ksp/interface/itfunc.c
Index of all KSP routines
Table of Contents for all manual pages
Index of all manual pages

### Examples

src/ksp/ksp/examples/tutorials/ex9.c.html
src/ksp/ksp/examples/tutorials/ex2f.F.html