[petsc-users] Segmentation Violation, is this a bug?

Matthew Knepley knepley at gmail.com
Thu Jun 24 18:39:21 CDT 2010


On Fri, Jun 25, 2010 at 7:25 AM, Li, Zhisong (lizs) <lizs at mail.uc.edu>wrote:

>
> Hi, Petsc Team,
>
> Recently I encounter a weird problem for segmentation violation. I wrote a
> simple test code to describe it. Here the line  " pp = sk[j+1][i].p; "
> causes segmentation violation trouble when I try to invoke values of ghost
> points in j direction. If I change it into "pp = sk[j][i+1].p;" invoking
> ghost point values in i diection, then it works smoothly. I check previous
> archives about segmentation violation, but cannot find any clue for this.
> Can you point out where is wrong here or is it a bug?
>

When you call DAVecGetArray() on a GLOBAL vector, there are no ghost values.
You need
a LOCAL vector. The i+1 is still wrong, but does not SEGV since you look
into memory you own.

   Matt


> Thank you.
>
>
> Zhisong Li
>
>
>
> static char help[] = "test";
> #include "petscda.h"
>
> typedef struct { PetscScalar p; } Field;
>
> int main(int argc, char **args)
> { Vec  xx;
>   PetscInt   dof = 1, m = 24, n= 32, i, j, xs, ys, xm, ym, yints, yinte,
> xints, xinte;
>   PetscScalar pp;
>   DA   da;
>   Field  **sk;
>   PetscInitialize(&argc, &args, (char *)0, help) ;
>
>   DACreate2d(PETSC_COMM_WORLD, DA_NONPERIODIC, DA_STENCIL_STAR, m, n,
> PETSC_DECIDE, PETSC_DECIDE, dof, 1, PETSC_NULL, PETSC_NULL, &da);
>   DACreateGlobalVector(da, &xx);
>   DAGetCorners(da, &xs, &ys, 0, &xm, &ym, 0);
>       xints = xs;   xinte = xs+xm;   yints = ys;   yinte = ys+ym;
>
>   VecSet(xx,1.0);
>
>   DAVecGetArray(da, xx, &sk);
>   if (xints == 0){ xints = xints + 1; }
>   if (yints == 0){ yints = yints + 1;
> }
>
>   if (xinte == m){ xinte = xinte - 1; }
>   if (yinte == n){ yinte = yinte - 1; }
>
>     for (j=yints; j<yinte; j++){
>       for (i=xints; i<xinte; i++)   { pp = sk[j+1][i].p; }
>                                }
>
>   DAVecRestoreArray(da, xx,
> &sk);
>   VecDestroy(xx);
>   DADestroy(da);
>   PetscFinalize();
>   PetscFunctionReturn(0);
> }
>
>


-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100625/892c878e/attachment-0001.htm>


More information about the petsc-users mailing list