Use of preconditioners

Issue #16 resolved
Blaž Starc created an issue

I am new to slepc4py and petsc4py and still learining the basics. I am trying to solve a generalized hermitian eigenvalue problem with a preconditioned eigensolver for first 10 smallest real eigenvalues. In my case I tried using HYPRE preconditioner with BLOPEX (LOBPCG) eigensolver:

# Matrices for generalized hermitian eigen problem
A.assemble() 
B.assemble()

# Solving the eigen problem
E = SLEPc.EPS().create()
method = E.Type.BLOPEX
problem_type=SLEPc.EPS.ProblemType.GHEP

pc = PETSc.PC()
pc.create()
pc.setType(pc.Type.HYPRE)

ksp = PETSc.KSP()
ksp.create()
ksp.setType(ksp.Type.PREONLY)
ksp.setTolerances(rtol=1E-4)
ksp.setPC( pc )


F = SLEPc.ST().create()
F.setType(F.Type.PRECOND)
F.setKSP( ksp )

# Setup the eigensolver    
E.setST(F)
E.setOperators(A, B)
E.setTolerances(tol=1e-3)
E.setType( method )
E.setDimensions(10, PETSc.DECIDE)
E.setProblemType( problem_type )
E.setFromOptions()

# Solve the eigensystem
E.solve()

The results are actually the same as with "pc.Type.NONE" or with "pc.Type.BJACOBI" (same iteration number, same values, approx. the same time). I would exepect an increase of speed with a PRECONDITIONER. It seems as the preconditioner is not used at all. Can someone point out the mistake I am making or even better, make a simple example on the use of preconditioners in combination with slepc4py?

p.s.: I made a comparison and the results match with the shift-and-inverted KrylovSchur method results

Comments (6)

  1. Jose E. Roman

    What do you mean by incorrect? Do you have a large residual? Do not use such a large tolerance 1e-1.

    Do not set F.setShift(0), instead you have to say E.setWhichEigenpairs(E.Which.SMALLEST_REAL)

    Also, you say the results are the same as with pc.Type.HYPRE. What are you using otherwise?

  2. Blaž Starc reporter

    Thank you Jose!

    I lowered the tolerance, so I get an expected result by value. I removed the F.setShift(0). The BLOPEX method finds the E.setWhichEigenpairs(E.Which.SMALLEST_REAL) by default.

    Aside from pc.Type.HYPRE, I used pc.Type.NONE and pc.Type.BJACOBI. I got the same results by all three methods: same values, same nr. of iterations and approx. the same time of computation. I would expect a better result by the use of preconditioner.

  3. Jose E. Roman

    By default, the preconditioner is built from A-sigma*B, so you can try F.setShift(sigma) for a sigma value located on the left of your spectrum (close to the first eigenvalue).

  4. Log in to comment