[petsc-users] question on VecPointwiseMax
Smith, Barry F.
bsmith at mcs.anl.gov
Tue Apr 17 16:24:05 CDT 2018
Where are you call SNESGetSolution() from? Inside a SNES monitor routine, a SNES convergence test routine, a SNESLineSearchPostCheck() routine?
The SNES linear solvers are solving the system, you really shouldn't be changing the values of the solution any time while they are doing their job solving the system. Of course you can change the values after the solver is done.
If you are trying to "solve" a linear system with upper and/or lower bounds on the variables you should solve it as a variational inequality and use SNESVISetVariableBounds(), you should not try to manually restrict the values (that won't work). And use -snes_type vinewtonrsls
Barry
Barry
> On Apr 17, 2018, at 12:04 PM, Xiangdong <epscodes at gmail.com> wrote:
>
> 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 VecPointwiseMax_Seq(Vec win,Vec xin,Vec yin)
> 17:
> {
>
> 19: PetscInt
> n = win->map->n,i;
>
> 20: PetscScalar *ww,*xx,*yy; /* cannot make xx or yy const since might be ww */
>
>
>
> 23: VecGetArrayRead(xin,(const PetscScalar
> **)&xx);
>
> 24: VecGetArrayRead(yin,(const PetscScalar
> **)&yy);
>
> 25: VecGetArray
> (win,&ww);
>
>
> 27: for (i=0; i<n; i++) ww[i] = PetscMax(PetscRealPart(xx[i]),
> PetscRealPart(yy[i]));
>
>
> 29: VecRestoreArrayRead(xin,(const PetscScalar
> **)&xx);
>
> 30: VecRestoreArrayRead(yin,(const PetscScalar
> **)&yy);
>
> 31: VecRestoreArray
> (win,&ww);
>
> 32: PetscLogFlops
> (n);
>
> 33: return
> (0);
>
> 34: }
> Can w and x really be same vector in the VecPointwiseMax? Thanks.
>
> Best,
> Xiangdong
>
More information about the petsc-users
mailing list