[petsc-users] Compute initial guess multiple times

Barry Smith bsmith at mcs.anl.gov
Fri Oct 9 13:49:25 CDT 2015


  The current model is a bit wonky.


    At the first call to KSPSolve after a call to KSPSetComputeOperators the computematrix, computerhs, and computeinitialguess are called. 

    In subsequent calls to KSPSolve ONLY the computerhs is called.

    So for example

      KSPSetComputeOperators()
      KSPSolve   -- computematrix, rhs, initial guess called
      KSPSolve  --- computerhs called
      KSPSetComputerOperators()
      KSPSolve   -- computematrix, rhs, initial guess called


   Note that the KSPSetCompute...() functions are just one particular way of using KSP.  You can also use the "standard" interface

     Set values into matrix and rhs and initial guess (call KSPSetInitialGuessNonzero) 
     KSPSolve(ksp,b,x)
     change values in b, this would use the current values in x as the initial guess for the next solve
     KSPSolve(ksp,b,x)
     change values in b and x
     KSPSolve()
     Change values in matrix and b and x (for initial guess)
     KSPSolve() 

    This gives you exact detailed control over when and what you set in initial guesses.

    Is there a particular reason for your problem that it is better to use the KSPSetCompute...() interface?

   Barry

  Note I wrote the KSPSetCompute...() interface so that PCMG could "build its own" coarse grid matrix values without the user needing to set values for all the levels before calling KSPSolve.


   
> On Oct 9, 2015, at 5:04 AM, Filippo Leonardi <filippo.leonardi at sam.math.ethz.ch> wrote:
> 
> So, I want to solve a system Ax = b multiple times, reuse A with different bs. 
> It is natural to set differents initial guesses each time for iterative 
> solvers.
> 
> And 
> KSPSetComputeInitialGuess(ksp,ComputeGuess,&user);
> is what PETSc provide for setting the Guess.
> 
> I am unsure if I am making something wrong, but it seems to me that this 
> function is called only once the matrix is first setted up. I want to be 
> called each time.
> 
> See my modified ex32.c for comparison.
> 
> ./ex32 -pc_type mg -pc_mg_type full -ksp_type fgmres -ksp_monitor_short -
> pc_mg_levels 3 -mg_coarse_pc_factor_shift_type nonzero -
> ksp_initial_guess_nonzero
> 
> Thanks.
> 
> Best,
> Filippo<ex32.c>



More information about the petsc-users mailing list