This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Clear PETScOptions?

+2 votes

I'm solving a series of linear problems, two of which use PETScOptions. Unfortunately, the PETScOptions are global (yikes!), so to avoid interference between the solvers, I'll have to manually clear them.

There's clear(), but it takes a string option, I suppose for the option I want cleared. However, I want to clear _all_ options.

If there's an alternative to PETScOptions that's doesn't have a global state, that'd be great to hear about as well.

Any hints?

asked Mar 31, 2017 by nschloe FEniCS User (7,120 points)

Hi, I asked the same question not long ago here, but didn't get an answer.

I found that there are probably 3 options: "Remember" all the options you set, and afterwards call PETScOptions().clear(opt) for each option. However, in my particular case, the fieldsplit_0_pc_ml_Threshold was not cleared... a bug in petsc I guess.
Maybe using the petsc4py interface directly works better, there is PETSc.Options().delValue() and .clear()..

The better option is to use the multiprocessing module to run your solve function in separate processes. If you set global PETScOptions there, at least there won't be any interference with the other processes. This is as close as I got to local options. Read this in a PETSc tutorial actually. Unfortunately (and annoyingly) sometimes the queues would hang..
Check out my question for small examples for each method.

I see something suspicious in the C++ source code, but it isn't exposed to Python: https://github.com/FEniCS/dolfin/blob/master/dolfin/la/PETScOptions.h#L80.

Hmm. petsc4py.PETSc.Options().clear() exists too and should do the job, but doesn't. Both are just wrappers for the PETSc method PETScOptionsClear()
https://bitbucket.org/petsc/petsc4py/src/fbe23a494ab485f44f00ee37eee9f8be8dcd9eb5/src/PETSc/Options.pyx?at=master&fileviewer=file-view-default#Options.pyx-47
There is a destroy() method, too...

The clear you're linking is a class method that calls clear on self.opt, so I guess it only gets rid of one. The unexposed clear() (without arguments) clears everything via PetscOptionsClear.

I don't think so. The petsc function for deleting a single option is PETScOptionsClearValue(), .clear() calls PETScOptionsClear(). I think self.opt refers to the complete set of options. Note how the getAll() function takes self.opt as an argument but returns all the options. But then I don't really know how the options are managed internally..
Thanks for filing the bug.

1 Answer

+2 votes
 
Best answer
answered Apr 4, 2017 by nschloe FEniCS User (7,120 points)
...