Hi dokken,
First of all thank you for looking into this and sorry for not making things clear.
I figured out in the mean time that the issue seems to be related to the options passed to the PETSc in the LinearProblem class. Taking your MWE and replacing
problem = dolfinx.fem.petsc.LinearProblem(a, L, [], uh)
with
problem = dolfinx.fem.petsc.LinearProblem(a, L, [], uh, petsc_options={"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"})
the code crashes eventually:
2%|▏ | 214/10000 [00:08<06:09, 26.52it/s]
---------------------------------------------------------------------------
Error Traceback (most recent call last)
Input In [3], in <cell line: 31>()
30 Nx = 50
31 for i in tqdm(range(N)):
---> 32 solve()
Input In [3], in solve()
23 a = ufl.inner(u, v) * ufl.dx
24 L = ufl.inner(g, v) * ufl.dx
---> 25 problem = dolfinx.fem.petsc.LinearProblem(a, L, [], uh, petsc_options={"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"})
26 problem.solve()
File /usr/local/dolfinx-real/lib/python3.10/dist-packages/dolfinx/fem/petsc.py:589, in LinearProblem.__init__(self, a, L, bcs, u, petsc_options, form_compiler_params, jit_params)
587 opts.prefixPush(problem_prefix)
588 for k, v in petsc_options.items():
--> 589 opts[k] = v
590 opts.prefixPop()
591 self._solver.setFromOptions()
File PETSc/Options.pyx:23, in petsc4py.PETSc.Options.__setitem__()
File PETSc/Options.pyx:91, in petsc4py.PETSc.Options.setValue()
Error: error code 55
[0] PetscOptionsSetValue() at /usr/local/petsc/src/sys/objects/options.c:1165
[0] PetscOptionsSetValue_Private() at /usr/local/petsc/src/sys/objects/options.c:1215
[0] Out of memory. Allocated: 0, Used by process: 154685440
[0] Number of options 512 < max number of options 512, can not allocate enough space
By copy-pasting the source code of LinearProblem() and inserting
...
588 for k, v in petsc_options.items():
589 opts[k] = v
590 print(opts.getAll())
591 opts.prefixPop()
I can confirm that the options somehow accumulate over iterations, and eventually exceed 512 which seems to be the limit on the number of options that PETSc allows.
Having identified this bug I can figure out a workaround for myself, but perhaps this is worth fixing in a future update?
All the best,
Alex