[petsc-users] question on VecPointwiseMax
Xiangdong
epscodes at gmail.com
Tue Apr 17 12:04:04 CDT 2018
Hello everyone,
Here are a little more information.
Here is the function calls I have:
SNESGetSolution(snes,&x);
VecPointwiseMax(x,x,xl); Fail
VecPointwiseMax(x,y,xl); Fail
The error messages are"Object is in wrong state, Vec is locked read only,
argument #1."
It seems that the vector x returned from SNESGetSolution is locked read
only, Is it true?
If I want do some post processing by modifying the x after each nonlinear
iteration, how can I get the solution and modify it?
Thank you.
Best,
Xiangdong
On Tue, Apr 17, 2018 at 11:33 AM, Xiangdong <epscodes at gmail.com> wrote:
> Hello everyone,
>
> When I call VecPointwiseMax(x,x,y) , I got an error message "object is in
> wrong state. Vec is locked read only, argument #1."
>
> However, In the online manual of output parameters of VecPointwiseMax, it
> says:
>
> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/
> VecPointwiseMax.html
> Output Parameter*w *-the result
>
> Notes: any subset of the x, y, and w may be the same vector. For complex
> numbers compares only the real part
> However, in the implementation of VecPointwiseMax_Seq,
> http://www.mcs.anl.gov/petsc/petsc-current/src/vec/vec/
> impls/seq/bvec2.c.html#VecPointwiseMax_Seq,
>
> it seems that xin is read locked, and win and xin cannot be the same
> vectors.
>
> *PetscErrorCode <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode> VecPointwiseMax_Seq(Vec <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/Vec.html#Vec> win,Vec <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/Vec.html#Vec> xin,Vec <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/Vec.html#Vec> yin)* 17: { 19: PetscInt <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt> n = win->map->n,i; 20: PetscScalar <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar> *ww,*xx,*yy; /* cannot make xx or yy const since might be ww */
> 23: VecGetArrayRead <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArrayRead.html#VecGetArrayRead>(xin,(const PetscScalar <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar>**)&xx); 24: VecGetArrayRead <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArrayRead.html#VecGetArrayRead>(yin,(const PetscScalar <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar>**)&yy); 25: VecGetArray <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArray.html#VecGetArray>(win,&ww);
> 27: for (i=0; i<n; i++) ww[i] = PetscMax <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscMax.html#PetscMax>(PetscRealPart(xx[i]),PetscRealPart(yy[i]));
> 29: VecRestoreArrayRead <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArrayRead.html#VecRestoreArrayRead>(xin,(const PetscScalar <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar>**)&xx); 30: VecRestoreArrayRead <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArrayRead.html#VecRestoreArrayRead>(yin,(const PetscScalar <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscScalar.html#PetscScalar>**)&yy); 31: VecRestoreArray <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArray.html#VecRestoreArray>(win,&ww); 32: PetscLogFlops <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Profiling/PetscLogFlops.html#PetscLogFlops>(n); 33: return(0); 34: }
>
> Can w and x really be same vector in the VecPointwiseMax? Thanks.
>
> Best,
> Xiangdong
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180417/53af4da9/attachment.html>
More information about the petsc-users
mailing list