Hello everyone,
I’m wondering if there is any way to save the LU factorization results of a PETSc KSP direct solver (i.e., only using the LU preconditioner) and load it somewhere else to create a direct solver to avoid the time-consuming LU re-factorization.
Here is a brief code snipplet to better explain what I want to do:
#imagine a Mat A
#create a solver based on A
solver = PETSc.KSP().create()
solver.setOperators(A)
solver.setType(PETSc.KSP.Type.PREONLY)
solver.getPC().setType(PETSc.PC.Type.LU)
#LU factorization, which is time-consuming
solver.setUp()
#solving for certain rhs, which is very fast
solver.solve(b, x)
Now I want to save the inner state, or specifically the factorized matrix related with the solver, and load it somewhere else to avoid the setUp()
stage. The factorized matrix can be accessed with solver.getPC().getFactorMatrix()
, and it seems that the Viewer
object of PETSc can help, but I haven’t found out a feasible routine.