<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div dir="ltr">
<div dir="ltr"><br>
<br>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Sat, Jul 20, 2019 at 5:47 AM José Lorenzo via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div>Hello,</div>
<div><br>
</div>
<div>I am not sure I understand the function VecGhostRestoreLocalForm. If I proceed as stated in the manual,<br>
</div>
<div><br>
</div>
<div>
<pre>    <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGhostUpdateBegin.html#VecGhostUpdateBegin" target="_blank">VecGhostUpdateBegin</a>(x,<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES" target="_blank">INSERT_VALUES</a>,<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/SCATTER_FORWARD.html#SCATTER_FORWARD" target="_blank">SCATTER_FORWARD</a>);
</pre>
<pre>    <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGhostUpdateEnd.html#VecGhostUpdateEnd" target="_blank">VecGhostUpdateEnd</a>(x,<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES" target="_blank">INSERT_VALUES</a>,<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/SCATTER_FORWARD.html#SCATTER_FORWARD" target="_blank">SCATTER_FORWARD</a>);
</pre>
<pre>    <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGhostGetLocalForm.html#VecGhostGetLocalForm" target="_blank">VecGhostGetLocalForm</a>(x,&xlocal);
</pre>
<pre>    <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGetArray.html#VecGetArray" target="_blank">VecGetArray</a>(xlocal,&xvalues);
</pre>
<pre>       // access the non-ghost values in locations xvalues[0:n-1] and ghost values in locations xvalues[n:n+nghost];
</pre>
<pre>    <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecRestoreArray.html#VecRestoreArray" target="_blank">VecRestoreArray</a>(xlocal,&xvalues);
</pre>
<pre>    <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecGhostRestoreLocalForm.html#VecGhostRestoreLocalForm" target="_blank">VecGhostRestoreLocalForm</a>(x,&xlocal)<br><br></pre>
<pre>Does VecRestoreArray update the values in the local vector xlocal, and then VecGhostRestoreLocalForm update the values of the global vector x? <br></pre>
</div>
</div>
</blockquote>
<div>Yes, you can think  VecRestoreArray finalizes the updates to xlocal. VecGhostRestoreLocalForm does not update global vector. It is for bookkeeping purposes.</div>
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 <span style="color:rgb(0,0,0)">
</span>VecGhostUpdateBegin/End after above code, for example, to ADD two ghosts.</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div>
<pre><br></pre>
<pre>Does one need to call these two functions?<br></pre>
</div>
</div>
</blockquote>
<div>Yes.  In PETSc, *Get and *Restore have to be paired.</div>
</div>
</div>
</body>
</html>