Force clear PETSc solver from memory?

The problem is a pure petsc issue:
MWE:

from petsc4py import PETSc
import gc
petsc_options = {"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps",
                 "petsc_options_left": None}


def add_options(prefix, petsc_options):
    opts = PETSc.Options()
    opts.prefixPush(prefix)
    for k, v in petsc_options.items():
        opts[k] = v
    opts.prefixPop()
    opts.clear()
    opts.destroy()
    del opts
    gc.collect()


for i in range(500):
    add_options(f"opts_{i}", petsc_options)

There seems to be no way of destroying or clearing the PETSc options once they have been initiated.

EDIT: I’ve made an issue at: PETSc.Options not cleared or destroyed in Python (#1201) · Issues · PETSc / petsc · GitLab

1 Like