[petsc-dev] is VecGetValuesSection correct?

Hapla Vaclav vaclav.hapla at erdw.ethz.ch
Fri Jun 21 06:14:48 CDT 2019


VecGetValuesSection() returns pointer values obtained as follows:

VecGetArray(v, &baseArray);
*values = &baseArray[s->atlasOff[p]];
VecRestoreArray(v, &baseArray);

It looks to me scary.
VecGetArray manpage says: If the underlying vector data is not stored in a contiguous array this routine will copy the data to a contiguous array and return a pointer to that.
VecRestoreArray manpage says: For any special vectors that do not store local vector data in a contiguous array, this routine will copy the data back into the underlying vector data structure from the array obtained with VecGetArray().

So I guess VecRestoreArray() is free to destroy that contiguous array, right?
In this case values would point to some nonsensical location in memory.

Thanks,
Vaclav


More information about the petsc-dev mailing list