<div dir="ltr">Hello everyone,<div><br></div><div>Here are a little more information.</div><div><br></div><div>Here is the function calls I have: </div><div><br></div><div>SNESGetSolution(snes,&x);</div><div>VecPointwiseMax(x,x,xl); Fail</div><div>VecPointwiseMax(x,y,xl); Fail</div><div><br></div><div>The error messages are"Object is in wrong state, Vec is locked read only, argument #1."</div><div><br></div><div>It seems that the vector x returned from SNESGetSolution is locked read only, Is it true? </div><div><br></div><div>If I want do some post processing by modifying the x after each nonlinear iteration, how can I get the solution and modify it?</div><div><br></div><div>Thank you.</div><div><br></div><div>Best,</div><div>Xiangdong</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 17, 2018 at 11:33 AM, Xiangdong <span dir="ltr"><<a href="mailto:epscodes@gmail.com" target="_blank">epscodes@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello everyone,<div><br></div><div>When I call VecPointwiseMax(x,x,y) , I got an error message "object is in wrong state. Vec is locked read only, argument #1."</div><div><br></div><div>However, In the online manual of output parameters of VecPointwiseMax, it says:<br></div><div><br></div><div><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecPointwiseMax.html" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>petsc-current/docs/<wbr>manualpages/Vec/<wbr>VecPointwiseMax.html</a><br></div><div><dt style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><h3><font color="#CC3333">Output Parameter</font></h3></dt><dt style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><b>w<span> </span></b>-the result<span> </span><br><p></p><p>Notes: any subset of the x, y, and w may be the same vector. For complex numbers compares only the real part</p></dt>However, in the implementation of VecPointwiseMax_Seq,</div><div><a href="http://www.mcs.anl.gov/petsc/petsc-current/src/vec/vec/impls/seq/bvec2.c.html#VecPointwiseMax_Seq" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>petsc-current/src/vec/vec/<wbr>impls/seq/bvec2.c.html#<wbr>VecPointwiseMax_Seq</a>, </div><div><br></div><div>it seems that xin is read locked, and win and xin cannot be the same vectors.</div><div><pre width="80" style="color:rgb(0,0,0);font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><a name="m_-5195668893712091257_line16"> </a><strong><font color="#4169E1"><a name="m_-5195668893712091257_VecPointwiseMax_Seq"></a><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode" target="_blank">PetscErrorCode</a> VecPointwiseMax_Seq(<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/Vec.html#Vec" target="_blank">Vec</a> win,<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/Vec.html#Vec" target="_blank">Vec</a> xin,<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/Vec.html#Vec" target="_blank">Vec</a> yin)</font></strong>
<a name="m_-5195668893712091257_line17"> 17: </a>{
<a name="m_-5195668893712091257_line19"> 19: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt" target="_blank">PetscInt</a> n = win->map->n,i;
<a name="m_-5195668893712091257_line20"> 20: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar" target="_blank">PetscScalar</a> *ww,*xx,*yy; <font color="#B22222">/* cannot make xx or yy const since might be ww */</font>
<a name="m_-5195668893712091257_line23"> 23: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArrayRead.html#VecGetArrayRead" target="_blank">VecGetArrayRead</a>(xin,(const <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar" target="_blank">PetscScalar</a>**)&xx);
<a name="m_-5195668893712091257_line24"> 24: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArrayRead.html#VecGetArrayRead" target="_blank">VecGetArrayRead</a>(yin,(const <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar" target="_blank">PetscScalar</a>**)&yy);
<a name="m_-5195668893712091257_line25"> 25: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArray.html#VecGetArray" target="_blank">VecGetArray</a>(win,&ww);
<a name="m_-5195668893712091257_line27"> 27: </a> <font color="#4169E1">for</font> (i=0; i<n; i++) ww[i] = <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscMax.html#PetscMax" target="_blank">PetscMax</a>(PetscRealPart(xx[i]),<wbr>PetscRealPart(yy[i]));
<a name="m_-5195668893712091257_line29"> 29: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArrayRead.html#VecRestoreArrayRead" target="_blank">VecRestoreArrayRead</a>(xin,(const <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar" target="_blank">PetscScalar</a>**)&xx);
<a name="m_-5195668893712091257_line30"> 30: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArrayRead.html#VecRestoreArrayRead" target="_blank">VecRestoreArrayRead</a>(yin,(const <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar" target="_blank">PetscScalar</a>**)&yy);
<a name="m_-5195668893712091257_line31"> 31: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArray.html#VecRestoreArray" target="_blank">VecRestoreArray</a>(win,&ww);
<a name="m_-5195668893712091257_line32"> 32: </a> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Profiling/PetscLogFlops.html#PetscLogFlops" target="_blank">PetscLogFlops</a>(n);
<a name="m_-5195668893712091257_line33"> 33: </a> <font color="#4169E1">return</font>(0);
<a name="m_-5195668893712091257_line34"> 34: </a>}</pre>Can w and x really be same vector in the VecPointwiseMax? Thanks.</div><div><br></div><div>Best,</div><div>Xiangdong</div></div>
</blockquote></div><br></div>