[petsc-users] DMDAVecGetArray vs DMDAVecRestoreArray
Alan Wei
zhenglun.wei at gmail.com
Thu Aug 18 20:07:55 CDT 2011
Dear Barry,
Thanks for your reply.
best,
Alan
On Thu, Aug 18, 2011 at 5:49 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
> On Aug 18, 2011, at 5:02 PM, Alan Wei wrote:
>
> > Dear all,
> > I hope you're having a nice day.
> > I'm trying to get the x, y-value of a coordinate created by
> DMDACreate2d. Lines I wrote down are:
> >
> > DMDAGetCoordinateDA(da, &cda);
> > DMDAGetGhostedCoordinates(da, &gc);
> > DMDAVecGetArray(cda, gc, &coors);
> >
> > for (i = xs; i < xs+xm; i++) {
> > for (j = ys; j < ys+ym; j++) {
> > printf("%f %f\n", coors[j][i].x, coors[j][i].y);
> > }
> > }
> >
> > DMDAVecRestoreArray(cda, gc, &coors);
> >
> > I wonder why I need to use "DMDAVecRestoreArray(cda, gc, &coors);" I used
> it because the manual said I need. Actually, I tried to comment it out and
> there is no difference.
> >
> > Thanks,
> > Alan
>
> The practical reason is you might get memory bleeding if you don't. The
> philosphical reason is that a call DMDAVecGetArray() or VecGetArray() or
> others is a request to access the internal data structure of an object, the
> object then gives you permission to access that data. the RestoreArray() is
> a statement by you that after this call you will NOT access that data
> directly (without another GetArray call). Imagine if you did
>
> Barry
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110818/1beb5627/attachment.htm>
More information about the petsc-users
mailing list