On Sat, Jul 20, 2019 at 5:47 AM José Lorenzo via petsc-users <petsc-users@mcs.anl.gov<mailto:petsc-users@mcs.anl.gov>> wrote: Hello, I am not sure I understand the function VecGhostRestoreLocalForm. If I proceed as stated in the manual, VecGhostUpdateBegin<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGhostUpdateBegin.html#VecGhostUpdateBegin>(x,INSERT_VALUES<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES>,SCATTER_FORWARD<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/SCATTER_FORWARD.html#SCATTER_FORWARD>); VecGhostUpdateEnd<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGhostUpdateEnd.html#VecGhostUpdateEnd>(x,INSERT_VALUES<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES>,SCATTER_FORWARD<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/SCATTER_FORWARD.html#SCATTER_FORWARD>); VecGhostGetLocalForm<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGhostGetLocalForm.html#VecGhostGetLocalForm>(x,&xlocal); VecGetArray<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArray.html#VecGetArray>(xlocal,&xvalues); // access the non-ghost values in locations xvalues[0:n-1] and ghost values in locations xvalues[n:n+nghost]; VecRestoreArray<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArray.html#VecRestoreArray>(xlocal,&xvalues); VecGhostRestoreLocalForm<https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGhostRestoreLocalForm.html#VecGhostRestoreLocalForm>(x,&xlocal) Does VecRestoreArray update the values in the local vector xlocal, and then VecGhostRestoreLocalForm update the values of the global vector x? Yes, you can think VecRestoreArray finalizes the updates to xlocal. VecGhostRestoreLocalForm does not update global vector. It is for bookkeeping purposes. x and xlocal share the same memory that contains the actual vector data. If you changed ghost points through xvalues[], to get the global vector x updated, you have to call VecGhostUpdateBegin/End after above code, for example, to ADD two ghosts. Does one need to call these two functions? Yes. In PETSc, *Get and *Restore have to be paired.
Re: [petsc-users] VecGhostRestoreLocalForm
Zhang, Junchao via petsc-users Sat, 20 Jul 2019 06:46:45 -0700