<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">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/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">http://www.mcs.anl.gov/petsc/petsc-current/src/vec/vec/impls/seq/bvec2.c.html#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="line16"> </a><strong><font color="#4169E1"><a name="VecPointwiseMax_Seq"></a><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> VecPointwiseMax_Seq(<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/Vec.html#Vec">Vec</a> win,<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/Vec.html#Vec">Vec</a> xin,<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/Vec.html#Vec">Vec</a> yin)</font></strong>
<a name="line17"> 17: </a>{
<a name="line19"> 19: </a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>       n = win->map->n,i;
<a name="line20"> 20: </a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a>    *ww,*xx,*yy; <font color="#B22222">/* cannot make xx or yy const since might be ww */</font>

<a name="line23"> 23: </a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArrayRead.html#VecGetArrayRead">VecGetArrayRead</a>(xin,(const <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a>**)&xx);
<a name="line24"> 24: </a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArrayRead.html#VecGetArrayRead">VecGetArrayRead</a>(yin,(const <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a>**)&yy);
<a name="line25"> 25: </a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArray.html#VecGetArray">VecGetArray</a>(win,&ww);

<a name="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">PetscMax</a>(PetscRealPart(xx[i]),PetscRealPart(yy[i]));

<a name="line29"> 29: </a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArrayRead.html#VecRestoreArrayRead">VecRestoreArrayRead</a>(xin,(const <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a>**)&xx);
<a name="line30"> 30: </a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArrayRead.html#VecRestoreArrayRead">VecRestoreArrayRead</a>(yin,(const <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a>**)&yy);
<a name="line31"> 31: </a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArray.html#VecRestoreArray">VecRestoreArray</a>(win,&ww);
<a name="line32"> 32: </a>  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Profiling/PetscLogFlops.html#PetscLogFlops">PetscLogFlops</a>(n);
<a name="line33"> 33: </a>  <font color="#4169E1">return</font>(0);
<a name="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>