[petsc-users] Compute initial guess multiple times

Leonardi Filippo filippo.leonardi at sam.math.ethz.ch
Fri Oct 9 13:58:57 CDT 2015


Actually I used to use KSPSolve directly, then I've started using KSPSetCompute... because (if I remember correctly) (as you mention) I wanted KSPComputeMatrix to compute all the coarse matrices for me.

Now I switched to completely use algebraic multigrid or galerkin computed matrices, so I can revert back to use the KSPSolve directly, but, for testing purposes, it may be good to keep being able to use PCMG.

My question now is: can I use SetComputeMatrix() and then call KSPSolve(ksp,b,x)? (I forgot if i need to use b,x = NULL or not when using the compute matrix routine.)
________________________________________
Da: Barry Smith [bsmith at mcs.anl.gov]
Inviato: venerdì 9 ottobre 2015 20.49
A: Leonardi  Filippo
Cc: petsc-users at mcs.anl.gov
Oggetto: Re: [petsc-users] Compute initial guess multiple times

  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