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

Li, Zhisong (lizs) lizs at mail.uc.edu
Thu Jun 24 18:25:15 CDT 2010


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?


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);
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100624/de175d04/attachment.htm>


More information about the petsc-users mailing list