[petsc-users] Correct way to access a sequential version of a DMDA Vec?

Ellen M. Price ellen.price at cfa.harvard.edu
Sun Oct 27 18:25:13 CDT 2019


Hi PETSc users!

I'm trying to access a DMDA Vec's values after doing a scatter to all
processors. I've run into some trouble, however, because the call to
DMDAVecGetArray doesn't seem to care that I'm using a sequential vector.
The calling sequence that "works" (runs without error *until* I try to
use the values) is:

// da is the 2-dimensional DMDA
// x is a global, input vector
// xs is the sequential vector
// values is an array of structs suitable for this DMDA

DMGetLocalVector(da, &xloc);
DMGlobalToLocalBegin(da, x, INSERT_VALUES, xloc);
DMGlobalToLocalEnd(da, x, INSERT_VALUES, xloc);
VecScatterCreateToAll(xloc, &scatter, &xs);
VecScatterBegin(scatter, xloc, xs, INSERT_VALUES, SCATTER_FORWARD);
VecScatterEnd(scatter, xloc, xs, INSERT_VALUES, SCATTER_FORWARD);
DMDAVecGetArrayRead(da, xs, &values);

>From a skim of the PETSc source code, it looks like the start parameters
that get handed off to VecGetArray2d only depend on the DMDA and do not
take into account that the vector might already be sequential. (I might
be wrong about this, but that's what it looks like at first glance.) Is
there a way around this that is more elegant than just modifying the
output pointer?

Feel free to point me to an applicable message board post if there is
one, but Google hasn't brought up anything useful yet.

Thanks,
Ellen Price


More information about the petsc-users mailing list