- edited description
Use of preconditioners
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)
-
reporter -
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 sayE.setWhichEigenpairs(E.Which.SMALLEST_REAL)
Also, you say the results are the same as with
pc.Type.HYPRE
. What are you using otherwise? -
reporter - edited description
updated the question based on jose's anweser
-
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 theE.setWhichEigenpairs(E.Which.SMALLEST_REAL)
by default.Aside from
pc.Type.HYPRE
, I usedpc.Type.NONE
andpc.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. -
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). -
- changed status to resolved
- Log in to comment