<html><body><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 f9d5775f43f69cbce5a7014a6ce3b24cc0e1214a (HEAD -> master, origin/master, origin/HEAD)<br><br>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><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/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><br>   ierr = PCShellGetContext(pc,(void**)&shell);CHKERRQ(ierr);<br>   ierr = VecPointwiseMult(y,x,shell->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 --------------------------------------------------------------<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><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><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..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><br>+  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><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 ?<br></div><div><br>Franck<br><br><br></div></div></body></html>