[petsc-dev] moving -xxx_view to XXXSetFromOptions()

Matthew Knepley knepley at gmail.com
Mon Sep 9 22:26:43 CDT 2013


On Mon, Sep 9, 2013 at 10:14 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
>     Previously we often checked the options for -xxx_view directly in
> various solvers and other pieces of code. For example in KSPSolve alone we
> have
>
>   ierr =
> PetscOptionsGetViewer(PetscObjectComm((PetscObject)ksp),((PetscObject)ksp)->prefix,"-ksp_view_pre",&viewer,&format,&flg);CHKERRQ(ierr);
>   if (flg && !PetscPreLoadingOn) {
>     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
>     ierr = KSPView(ksp,viewer);CHKERRQ(ierr);
>     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
>     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
>   }
>
>   ierr =
> MatViewFromOptions(mat,((PetscObject)ksp)->prefix,"-ksp_view_mat");CHKERRQ(ierr);
>   ierr =
> MatViewFromOptions(premat,((PetscObject)ksp)->prefix,"-ksp_view_pmat");CHKERRQ(ierr);
>   ierr =
> VecViewFromOptions(ksp->vec_rhs,((PetscObject)ksp)->prefix,"-ksp_view_rhs");CHKERRQ(ierr);
>
>   ierr =
> PetscOptionsHasName(((PetscObject)ksp)->prefix,"-ksp_view_mat_explicit",&flag2);CHKERRQ(ierr);
>   if (flag2) {
>     Mat A,B;
>     ierr = PCGetOperators(ksp->pc,&A,NULL,NULL);CHKERRQ(ierr);
>     ierr = MatComputeExplicitOperator(A,&B);CHKERRQ(ierr);
>     ierr =
> MatViewFromOptions(B,((PetscObject)ksp)->prefix,"-ksp_view_mat_explicit");CHKERRQ(ierr);
>     ierr = MatDestroy(&B);CHKERRQ(ierr);
>   }
>   ierr =
> PetscOptionsHasName(((PetscObject)ksp)->prefix,"-ksp_view_preconditioned_operator_explicit",&flag2);CHKERRQ(ierr);
>   if (flag2) {
>     Mat B;
>     ierr = KSPComputeExplicitOperator(ksp,&B);CHKERRQ(ierr);
>     ierr =
> MatViewFromOptions(B,((PetscObject)ksp)->prefix,"-ksp_view_preconditioned_operator_explicit");CHKERRQ(ierr);
>     ierr = MatDestroy(&B);CHKERRQ(ierr);
>   }
>   ierr =
> PetscOptionsGetViewer(PetscObjectComm((PetscObject)ksp),((PetscObject)ksp)->prefix,"-ksp_view",&viewer,&format,&flg);CHKERRQ(ierr);
>   if (flg && !PetscPreLoadingOn) {
>     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
>     ierr = KSPView(ksp,viewer);CHKERRQ(ierr);
>     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
>     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
>   }
>
>    I think these actually belong in KSPSetFromOptions(). Note that
> currently these do not have help messages nor would they go into any GUI
> option setting system plus the options may be checked many times outside
> the control of the user.
>
> The problem is many of them involve creating a viewer object (and format)
> which must be destroyed later. I propose putting them all in
> XXXSetFromOptions() and with each one using a PetscObjectCompose() to
> attach them to the XXX object so that when the XXX object is destroyed these
> viewers are suitably destroyed.
>
>    Does anyone see a better alternative?


This has a problem if you follow your reasoning about Vec. You did not want
VecSetFromOptions called internally, which
is a good thing because users should be in charge of configuration.
However, viewing is not configuration, so I would
propose a split of diagnostic options, which should probably always be
accepted, and configuration options, which should
depend on calling SetFromOptions(). I have not better idea than
ViewFromOptions().

    Matt


>
>     Barry
>
>
>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20130909/46411ceb/attachment.html>


More information about the petsc-dev mailing list