[petsc-users] accessing DMDA Vec ghost values

Sean Dettrick sdettrick at trialphaenergy.com
Thu May 12 04:42:54 CDT 2016


Hi,

When discussing DMDAVecGetArrayDOF etc in section 2.4.4,  the PETSc 3.7 manual says "The array is accessed using the usual global indexing on the entire grid, but the user may only refer to the local and ghost entries of this array as all other entries are undefined”.

OK so far.  But how to access the ghost entries?

With a 2D DMDA, I can do this OK:


        PetscInt    xs,xm,ys,ym;

        ierr=DMDAGetCorners(da,&xs,&ys,0,&xm,&ym,0);CHKERRQ(ierr);

        PetscScalar ***es;

        ierr=DMDAVecGetArrayDOF(da,Es,&es);CHKERRQ(ierr);


        for (int j=ys; j < ys+ym; j++) {

            for (int i=xs; i < xs+xm;i++) {

es[j][i][0]=1.;

                es[j][i][1]=1.;

            }

        }

        ierr=DMDAVecRestoreArrayDOF(da,Es,&es);CHKERRQ(ierr);

But if I replace DMDAGetCorners with DMDAGetGhostCorners, then the code crashes with a seg fault, presumably due to out of bounds memory access.

Is that supposed to happen?  What’s the remedy?

Thanks very much!

Sean Dettrick

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160512/e3b1d3c6/attachment.html>


More information about the petsc-users mailing list