On Aug 31, 2010, at 1:07 PM, Jed Brown wrote: > On Tue, 31 Aug 2010 11:21:02 -0300, Lisandro Dalcin <dalcinl at gmail.com> > wrote: >> Calling VecGetArray multiple times on the same vec seems to work (at >> least for native vectors). However, in VecSeq impl there is code to >> prevent such usage. What's the correct usage? > > I think that correct usage should not allow multiple access to the same > vector, so that VecGetArray implies exclusive access.
This was the intention. Only one writer could access at a time (several can use VecGetArrayRead() at the same time but there cannot be a writer at the same time). The code that generated an error with multiple access dissolved over time leaving that one useless fragment in the VecGetArray_Seq() which is not used. It would be nice if it was put back in (note by putting the flag into the _p_Vec structure you don't need a function call to do the error checking). Barry > I think PETSc is > consistent about this internally and it just doesn't check for native > vectors to avoid a function call. > > VecGetArray(X,&x); > VecGetArray(X,&y); > FunctionAssumingNoAliasing(x,y); > VecRestoreArray(X,&x); /* Is it safe to free buffer/move to GPU? */ > y[0] = 2.; /* If so, then this line is invalid. */ > > Jed
