<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><br>I am running debian (gcc-6.4), using petsc-dev synchronized on:<br>>> git log<br>commit f9d5775f43f69cbce5a7014a6ce3b2<wbr>4cc0e1214a (HEAD -> master, origin/master, origin/HEAD)<br><br>when I run petsc/src/ksp/ksp/examples/<wbr>tutorials/ex15.c, I get:<br>>> mpirun -n 2 ./ex15.exe -user_defined_pc<br>Norm of error 5.90715e-08 iterations 15<br><br>OK, so far, so good.<br><br>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/<wbr>tutorials/ex15.c b/src/ksp/ksp/examples/<wbr>tutorials/ex15.c<br>index badccd93b5..482e5ae6b5 100644<br>--- a/src/ksp/ksp/examples/<wbr>tutorials/ex15.c<br>+++ b/src/ksp/ksp/examples/<wbr>tutorials/ex15.c<br>@@ -296,6 +296,7 @@ PetscErrorCode SampleShellPCApply(PC pc,Vec x,Vec y)<br><br>   ierr = PCShellGetContext(pc,(void**)&<wbr>shell);CHKERRQ(ierr);<br>   ierr = VecPointwiseMult(y,x,shell-><wbr>diag);CHKERRQ(ierr);<br>+  ierr = VecSet(x, 0.);CHKERRQ(ierr);<br><br>   return 0;<br> }<br>>> mpirun -n 2 ./ex15.exe -user_defined_pc<br>[0]PETSC ERROR: --------------------- Error Message ------------------------------<wbr>------------------------------<wbr>--<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/<wbr>INRIA/petsc/src/vec/vec/<wbr>interface/rvector.c<br>[1]PETSC ERROR: #2 SampleShellPCApply() line 299 in /home/fghoussen/Documents/<wbr>INRIA/petsc/local/../src/ksp/<wbr>ksp/examples/tutorials/ex15.c<br><br>Why is that ? Is there a way to "unlock" x ?<br><br>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/<wbr>tutorials/ex15.c b/src/ksp/ksp/examples/<wbr>tutorials/ex15.c<br>index badccd93b5..98ae001319 100644<br>--- a/src/ksp/ksp/examples/<wbr>tutorials/ex15.c<br>+++ b/src/ksp/ksp/examples/<wbr>tutorials/ex15.c<br>@@ -294,6 +294,7 @@ PetscErrorCode SampleShellPCApply(PC pc,Vec x,Vec y)<br>   SampleShellPC  *shell;<br>   PetscErrorCode ierr;<br><br>+  ierr = VecSet(y, 0.);CHKERRQ(ierr);<br>   ierr = PCShellGetContext(pc,(void**)&<wbr>shell);CHKERRQ(ierr);<br>   ierr = VecPointwiseMult(y,x,shell-><wbr>diag);CHKERRQ(ierr);<br>>> mpirun -n 2 ./ex15.exe -user_defined_pc<br>Norm of error 5.90715e-08 iterations 15<br><br>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><br>If possible, I would like to reuse x (avoiding to re-create a vector) ? Is there a way to "unlock" x ?<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div><br>Franck<br><br><br></div></font></span></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="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>