Put what you want in x and use the option -ksp_initial_guess_nonzero (KSPSetInitialGuessNonzero).
Tolerances can be adjusted using options as well (KSPSetTolerances).

Thank you. Regarding the tolerance to stop the iteration:
I know -ksp_atol for ||Ax_n- b|| < tol
and -ksp_rtol for ||Ax_n- b|| / ||Ax_0- b|| < tol

However, I cannot find one key word to do: ||Ax_n- b|| / ||b|| < tol (equivalent to use -ksp_rtol when the initial guess x_0= 0)
or ||Ax_{n+1}- b|| / ||Ax_n- b|| < tol

Your equation for -ksp_rtol is wrong, please have a look at page 68 of https://petsc.org/release/docs/manual/manual.pdf. The fact that your initial guess is zero or not does not change how these equations are evaluated, b is always b, x_n is always x_n (x_0 is either 0 or what you supply if you use -ksp_initial_guess_nonzero).

I just realized that when I am solving my linear system with reusing the LU factorization (discussed in this topic, I am not using the option -ksp_initial_guess_nonzero true option, with which the solution time can be reduced even further. However, when I am trying to switch on and off -ksp_initial_guess_nonzero similarly to ksp_reuse_preconditioner, I get a strange error message

[0]PETSC ERROR: Running KSP of preonly doesn’t make sense with nonzero initial guess
you probably want a KSP type of Richardson

I also made an MWE which reproduces this behavior with some small modifications to the Stokes-PETSc example. Could you please take a look at this, and suggest a possible solution to this problem? stokes-2d-PETSc.edp (1.6 KB)

Sorry for bothering once again. I try to circumvent the issue in the meantime with defining an additional Mat to which no KSP parameters are attached, and using that to override the ksp param. However, when I copy a Mat, the partition of unity (Mat.D) does not seem to be copied. I also attach a reproducer. I can just store the partition of unity in a vector of course, but I am curious whether this is intentional, or is this a bug? partofUnity.edp (674 Bytes)

This is intentional. When you copy a Mat (using either the constructor Mat B(A) or B = A), the domain decomposition information (such as the partition of unity) from A is not carried over to B.

Furthermore, thanks for the fix in PETSc - I just compiled the most recent version in which the merge is accepted, and setting on and off -ksp_initial_guess_nonzero works perfectly!