[petsc-dev] Can I modify x on SampleShellPCApply callback ?

Matthew Knepley knepley at gmail.com
Sun Jul 16 08:59:09 CDT 2017


On Sun, Jul 16, 2017 at 8:51 AM, Franck Houssen <franck.houssen at inria.fr>
wrote:

> Can I modify x on SampleShellPCApply callback ?
>
> I am running debian (gcc-6.4), using petsc-dev synchronized on:
> >> git log
> commit f9d5775f43f69cbce5a7014a6ce3b24cc0e1214a (HEAD -> master,
> origin/master, origin/HEAD)
>
> when I run petsc/src/ksp/ksp/examples/tutorials/ex15.c, I get:
> >> mpirun -n 2 ./ex15.exe -user_defined_pc
> Norm of error 5.90715e-08 iterations 15
>
> OK, so far, so good.
>
> Now, I just modify x in SampleShellPCApply (reset to 0. at the end = doing
> nothing):
> >> git diff
> diff --git a/src/ksp/ksp/examples/tutorials/ex15.c b/src/ksp/ksp/examples/
> tutorials/ex15.c
> index badccd93b5..482e5ae6b5 100644
> --- a/src/ksp/ksp/examples/tutorials/ex15.c
> +++ b/src/ksp/ksp/examples/tutorials/ex15.c
> @@ -296,6 +296,7 @@ PetscErrorCode SampleShellPCApply(PC pc,Vec x,Vec y)
>
>    ierr = PCShellGetContext(pc,(void**)&shell);CHKERRQ(ierr);
>    ierr = VecPointwiseMult(y,x,shell->diag);CHKERRQ(ierr);
> +  ierr = VecSet(x, 0.);CHKERRQ(ierr);
>
>    return 0;
>  }
> >> mpirun -n 2 ./ex15.exe -user_defined_pc
> [0]PETSC ERROR: --------------------- Error Message
> --------------------------------------------------------------
> [0]PETSC ERROR: Object is in wrong state
> [0]PETSC ERROR:  Vec is locked read only, argument # 1
> [1]PETSC ERROR: #1 VecSet() line 547 in /home/fghoussen/Documents/
> INRIA/petsc/src/vec/vec/interface/rvector.c
> [1]PETSC ERROR: #2 SampleShellPCApply() line 299 in
> /home/fghoussen/Documents/INRIA/petsc/local/../src/ksp/
> ksp/examples/tutorials/ex15.c
>
> Why is that ? Is there a way to "unlock" x ?
>
> It seems, it's possible to modify y but not x: why ?
>

x is the input and should be read-only. Changes cannot have any
mathematical significance because you cannot know
where the x vector would be used subsequently anyway.

   Matt

  Matt


> >> git diff
> diff --git a/src/ksp/ksp/examples/tutorials/ex15.c b/src/ksp/ksp/examples/
> tutorials/ex15.c
> index badccd93b5..98ae001319 100644
> --- a/src/ksp/ksp/examples/tutorials/ex15.c
> +++ b/src/ksp/ksp/examples/tutorials/ex15.c
> @@ -294,6 +294,7 @@ PetscErrorCode SampleShellPCApply(PC pc,Vec x,Vec y)
>    SampleShellPC  *shell;
>    PetscErrorCode ierr;
>
> +  ierr = VecSet(y, 0.);CHKERRQ(ierr);
>    ierr = PCShellGetContext(pc,(void**)&shell);CHKERRQ(ierr);
>    ierr = VecPointwiseMult(y,x,shell->diag);CHKERRQ(ierr);
> >> mpirun -n 2 ./ex15.exe -user_defined_pc
> Norm of error 5.90715e-08 iterations 15
>
> Does PETSc uses x even after the callback has been called ?
> My understanding is that at the end of the callback only y matters: y
> replaces x that has become no-use (y is the new residu): am I wrong ?
>
> If possible, I would like to reuse x (avoiding to re-create a vector) ? Is
> there a way to "unlock" x ?
>
> Franck
>
>
>


-- 
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

http://www.caam.rice.edu/~mk51/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20170716/d934ac00/attachment.html>


More information about the petsc-dev mailing list