[petsc-dev] VecGetArrayRead vs. VecGetArrayPrivate

Barry Smith bsmith at mcs.anl.gov
Mon Nov 22 21:57:13 CST 2010


   Hg pull; hg update before reading this.

   VecGet/RestoreArrayRead() is suppose to be read only. VecGet/RestoreArray() is read/write and increases the state of the vector. These are the standard public methods.


   VecGetArrayPrivate() is read/write but DOES NOT increase the state of the vector directly, this is used by Vector operations that manage the change in state themselves. For example VecGetArrayPrivate() is used in, for example VecScale_Seq() because the VecScale() outer method manages increasing the state and preserving the norm value if it was set. If we used VecGetArrayRead() in that location (and did not have VecGetArrayPrivate() it would be very confusing since in VecScale_Seq() it does change the values so read is not appropriate but VecGetArray() would result in a double increase in the state and hence lose the VecNorm cached.

   In looking at the code now I make the following observation. The state increase operation being given inside the outer method (for example VecScale) comes from the days when the individual implementations (like VecScale_Seq) did not call VecGetArray....() but just accessed the array inside the structure directly.  We then went to the model where NO method (like VecScale_Seq) was ever suppose to directly access the array and always when through a VecGetArray....(), I had to introduce the VecGetArrayPrivate() to avoid double increasing the state of the vector (and thus losing some cached VecNorms).  I think if we removed ALL the increase state from the outer methods (like VecScale) we could remove the VecGetArrayPrivate() and always use VecGetArray() or write ones and VecGetArrayRead() for read ones inside the private methods. This has to be done with care, if all agree I'll do it.


   Barry


On Nov 22, 2010, at 8:54 PM, Matthew Knepley wrote:

> Why would you use Private, since Read jsut seems to call it?
> 
>   Thanks,
> 
>      Matt
> 
> -- 
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
> -- Norbert Wiener




More information about the petsc-dev mailing list