<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div>The pc (shell) I try to write is made of 2 levels.</div><div>I use y to "store" the contribution of the 1st level as I possibly need to reuse y for the 2nd level.</div><div> I wanted to use x to "store" the contribution of the 2nd level (for that, need possibly to reuse y), to finally return y += x.<br></div><div>This would have made less code (create, destroy, data in context, ...) to deal with.<br></div><div><br></div><div>Not such a big deal anyway<br></div><div><br></div><div>Franck<br></div><div><br></div><div><br></div><hr id="zwchr"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Matthew Knepley" <knepley@gmail.com><br><b>À: </b>"Franck Houssen" <franck.houssen@inria.fr><br><b>Cc: </b>"petsc-dev" <petsc-dev@mcs.anl.gov><br><b>Envoyé: </b>Dimanche 16 Juillet 2017 16:09:34<br><b>Objet: </b>Re: [petsc-dev] Can I modify x on SampleShellPCApply callback ?<br><div><br></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Jul 16, 2017 at 9:07 AM, Franck Houssen <span dir="ltr"><<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>OK, so I need to create a new x. Thanks for the quick answer.</div></div></div></blockquote><div><br></div><div>Why would you create a new x. There is some misunderstanding about this routine. You</div><div>should never need to create a "new x".</div><div><br></div><div>  Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>Franck<br></div><div><br></div><div><br></div><hr id="m_8105288681420075090zwchr"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>De: </b>"Matthew Knepley" <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>><br><b>Cc: </b>"petsc-dev" <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>><br><b>Envoyé: </b>Dimanche 16 Juillet 2017 15:59:09<br><b>Objet: </b>Re: [petsc-dev] Can I modify x on SampleShellPCApply callback ?<br><div><br></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Jul 16, 2017 at 8:51 AM, Franck Houssen <span dir="ltr"><<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>Can I modify x on SampleShellPCApply callback ?<br><div><br></div>I am running debian (gcc-6.4), using petsc-dev synchronized on:<br>>> git log<br>commit f9d5775f43f69cbce5a7014a6ce3b24cc0e1214a (HEAD -> master, origin/master, origin/HEAD)<br><div><br></div>when I run petsc/src/ksp/ksp/examples/tutorials/ex15.c, I get:<br>>> mpirun -n 2 ./ex15.exe -user_defined_pc<br>Norm of error 5.90715e-08 iterations 15<br><div><br></div>OK, so far, so good.<br><div><br></div>Now, I just modify x in SampleShellPCApply (reset to 0. at the end = doing nothing):<br>>> git diff<br>diff --git a/src/ksp/ksp/examples/tutorials/ex15.c b/src/ksp/ksp/examples/tutorials/ex15.c<br>index badccd93b5..482e5ae6b5 100644<br>--- a/src/ksp/ksp/examples/tutorials/ex15.c<br>+++ b/src/ksp/ksp/examples/tutorials/ex15.c<br>@@ -296,6 +296,7 @@ PetscErrorCode SampleShellPCApply(PC pc,Vec x,Vec y)<br><div><br></div>   ierr = PCShellGetContext(pc,(void**)&shell);CHKERRQ(ierr);<br>   ierr = VecPointwiseMult(y,x,shell->diag);CHKERRQ(ierr);<br>+  ierr = VecSet(x, 0.);CHKERRQ(ierr);<br><div><br></div>   return 0;<br> }<br>>> mpirun -n 2 ./ex15.exe -user_defined_pc<br>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>[0]PETSC ERROR: Object is in wrong state<br>[0]PETSC ERROR:  Vec is locked read only, argument # 1<br>[1]PETSC ERROR: #1 VecSet() line 547 in /home/fghoussen/Documents/INRIA/petsc/src/vec/vec/interface/rvector.c<br>[1]PETSC ERROR: #2 SampleShellPCApply() line 299 in /home/fghoussen/Documents/INRIA/petsc/local/../src/ksp/ksp/examples/tutorials/ex15.c<br><div><br></div>Why is that ? Is there a way to "unlock" x ?<br><div><br></div>It seems, it's possible to modify y but not x: why ?<br></div></div></div></blockquote><div><br></div><div>x is the input and should be read-only. Changes cannot have any mathematical significance because you cannot know</div><div>where the x vector would be used subsequently anyway.</div><div><br></div><div>   Matt</div><div><br></div><div>  Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div>>> git diff<br>diff --git a/src/ksp/ksp/examples/tutorials/ex15.c b/src/ksp/ksp/examples/tutorials/ex15.c<br>index badccd93b5..98ae001319 100644<br>--- a/src/ksp/ksp/examples/tutorials/ex15.c<br>+++ b/src/ksp/ksp/examples/tutorials/ex15.c<br>@@ -294,6 +294,7 @@ PetscErrorCode SampleShellPCApply(PC pc,Vec x,Vec y)<br>   SampleShellPC  *shell;<br>   PetscErrorCode ierr;<br><div><br></div>+  ierr = VecSet(y, 0.);CHKERRQ(ierr);<br>   ierr = PCShellGetContext(pc,(void**)&shell);CHKERRQ(ierr);<br>   ierr = VecPointwiseMult(y,x,shell->diag);CHKERRQ(ierr);<br>>> mpirun -n 2 ./ex15.exe -user_defined_pc<br>Norm of error 5.90715e-08 iterations 15<br><div><br></div>Does PETSc uses x even after the callback has been called ?<br>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 ?<br><div><br></div>If possible, I would like to reuse x (avoiding to re-create a vector) ? Is there a way to "unlock" x ?<span class="m_8105288681420075090HOEnZb"><span style="color:#888888"><br></span></span></div><span class="m_8105288681420075090HOEnZb"><span style="color:#888888"><div><br>Franck<br><div><br></div><br></div></span></span></div></div></blockquote></div><br><br clear="all"><span class="HOEnZb"><span data-mce-style="color: #888888;" style="color: #888888;"><div><br></div>-- <br><div class="m_8105288681420075090gmail_signature"><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.caam.rice.edu/~mk51/" target="_blank">http://www.caam.rice.edu/~mk51/</a><br></div></div></div>
</span></span></div></div>
</blockquote><div><br></div></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.caam.rice.edu/~mk51/" target="_blank">http://www.caam.rice.edu/~mk51/</a><br></div></div></div>
</div></div>
</blockquote><div><br></div></div></body></html>