Firedrake PETSc options_left
Dear all, PETSc options "-options_left" and "-log_view" seem to have no effect when setting as solver_parameters. I can prescribe them from the command line, but then I do not get the Firedrake/PETSc "options_left". How can I print the Firedrake/PETSc options_left. Thank you! Henrik -- Dipl.-Math. Henrik Büsing Institute for Applied Geophysics and Geothermal Energy E.ON Energy Research Center RWTH Aachen University ------------------------------------------------------ Mathieustr. 10 | Tel +49 (0)241 80 49907 52074 Aachen, Germany | Fax +49 (0)241 80 49889 ------------------------------------------------------ http://www.eonerc.rwth-aachen.de/GGE hbuesing@eonerc.rwth-aachen.de ------------------------------------------------------
Hi Henrik, On 23/03/17 13:47, Buesing, Henrik wrote:
Dear all,
PETSc options „-options_left“ and „-log_view“ seem to have no effect when setting as solver_parameters. I can prescribe them from the command line, but then I do not get the Firedrake/PETSc “options_left”.
How can I print the Firedrake/PETSc options_left. Thank you!
You need to pass "-log_view" as a commandline option, because by default, all options inside solver_parameters are prefixed by a custom prefix (so that solvers do not interfere with each other). You can set the options prefix for each solver individually using the options_prefix keyword argument (that allows you to control the solver options from the command line easily). However, so that we do not overflow the (static size) PETSc options database, the way we work with options is as follows: You say: solve(..., solver_parameters={...}) We insert the specified options into the options database, call setFromOptions on the PETSc KSP/SNES, call KSP/SNESSolve and then remove the options from the options database. Therefore, PETSc never sees any options in the database at the end of the program, so -options_left doesn't report anything. If you treat Firedrake solvers like PETSc ones and always set an options_prefix and only ever control them via options from the command-line, the -options_left will work: e.g. from firedrake import * mesh = UnitSquareMesh(1, 1) V = FunctionSpace(mesh, 'DG', 0) u = TrialFunction(V) v = TestFunction(V) a = u*v*dx L = v*dx u = Function(V) solve(a == L, u, options_prefix="") and then: $ python foo.py -options_left -ksp_type cg -pc_fieldsplit_type additive #PETSc Option Table entries: -ksp_type cg -options_left -pc_fieldsplit_type additive #End of PETSc Option Table entries There is one unused database option. It is: Option left: name:-pc_fieldsplit_type value: additive However, if you set that same option via the solver_parameters: from firedrake import * mesh = UnitSquareMesh(1, 1) V = FunctionSpace(mesh, 'DG', 0) u = TrialFunction(V) v = TestFunction(V) a = u*v*dx L = v*dx u = Function(V) solve(a == L, u, options_prefix="", solver_parameters={"pc_fieldsplit_type": "additive"}) $ python bar.py -options_left -ksp_type cg #PETSc Option Table entries: -ksp_type cg -options_left #End of PETSc Option Table entries There are no unused options. So you can see that PETSc doesn't even think, when the program exits, that pc_fieldsplit_type is in the options database, hence it is not an unused option. It might be possible to programmatically query the options database inside the solve call to see what options have been used, but I'm not sure. Lawrence
Dear Lawrence, Thank you for the explanation! Setting options_prefix="" and controlling everything from the command line is totally fine for me. Best, Henrik -- Dipl.-Math. Henrik Büsing Institute for Applied Geophysics and Geothermal Energy E.ON Energy Research Center RWTH Aachen University ------------------------------------------------------ Mathieustr. 10 | Tel +49 (0)241 80 49907 52074 Aachen, Germany | Fax +49 (0)241 80 49889 ------------------------------------------------------ http://www.eonerc.rwth-aachen.de/GGE hbuesing@eonerc.rwth-aachen.de ------------------------------------------------------
-----Ursprüngliche Nachricht----- Von: firedrake-bounces@imperial.ac.uk [mailto:firedrake- bounces@imperial.ac.uk] Im Auftrag von Lawrence Mitchell Gesendet: 23 March 2017 15:03 An: firedrake@imperial.ac.uk Betreff: Re: [firedrake] Firedrake PETSc options_left
Hi Henrik,
On 23/03/17 13:47, Buesing, Henrik wrote:
Dear all,
PETSc options "-options_left" and "-log_view" seem to have no effect when setting as solver_parameters. I can prescribe them from the command line, but then I do not get the Firedrake/PETSc "options_left".
How can I print the Firedrake/PETSc options_left. Thank you!
You need to pass "-log_view" as a commandline option, because by default, all options inside solver_parameters are prefixed by a custom prefix (so that solvers do not interfere with each other).
You can set the options prefix for each solver individually using the options_prefix keyword argument (that allows you to control the solver options from the command line easily).
However, so that we do not overflow the (static size) PETSc options database, the way we work with options is as follows:
You say:
solve(..., solver_parameters={...})
We insert the specified options into the options database, call setFromOptions on the PETSc KSP/SNES, call KSP/SNESSolve and then remove the options from the options database.
Therefore, PETSc never sees any options in the database at the end of the program, so -options_left doesn't report anything.
If you treat Firedrake solvers like PETSc ones and always set an options_prefix and only ever control them via options from the command- line, the -options_left will work:
e.g.
from firedrake import *
mesh = UnitSquareMesh(1, 1) V = FunctionSpace(mesh, 'DG', 0) u = TrialFunction(V) v = TestFunction(V)
a = u*v*dx L = v*dx
u = Function(V) solve(a == L, u, options_prefix="")
and then:
$ python foo.py -options_left -ksp_type cg -pc_fieldsplit_type additive #PETSc Option Table entries: -ksp_type cg -options_left -pc_fieldsplit_type additive #End of PETSc Option Table entries There is one unused database option. It is: Option left: name:-pc_fieldsplit_type value: additive
However, if you set that same option via the solver_parameters:
from firedrake import *
mesh = UnitSquareMesh(1, 1) V = FunctionSpace(mesh, 'DG', 0) u = TrialFunction(V) v = TestFunction(V)
a = u*v*dx L = v*dx
u = Function(V) solve(a == L, u, options_prefix="", solver_parameters={"pc_fieldsplit_type": "additive"})
$ python bar.py -options_left -ksp_type cg #PETSc Option Table entries: -ksp_type cg -options_left #End of PETSc Option Table entries There are no unused options.
So you can see that PETSc doesn't even think, when the program exits, that pc_fieldsplit_type is in the options database, hence it is not an unused option.
It might be possible to programmatically query the options database inside the solve call to see what options have been used, but I'm not sure.
Lawrence
On 23/03/17 14:25, Buesing, Henrik wrote:
Dear Lawrence,
Thank you for the explanation! Setting
options_prefix=""
and controlling everything from the command line is totally fine for me.
Note that if you have more than one different solve, you should give each solve a different options_prefix, so that you can control each one separately: e.g. solve(a == L, ..., options_prefix="foo_") solve(b == C, ..., options_prefix="bar_") now -foo_ksp_type cg -bar_ksp_type gmres Sets the KSP type of the first solve to be CG, but the second to be GMRES. Lawrence
participants (2)
- 
                
                Buesing, Henrik
- 
                
                Lawrence Mitchell