[petsc-users] How to access the value uarray[j+2][i]
Fatcharm
wolfshow at gmail.com
Wed Dec 21 01:04:42 CST 2011
Dear All PETSc users,
I am dealing with the fuction 'FormIFunction' which is simalar to the
one used in the /petsc-3.2-p5/src/ts/examples/tutorials/ex15.c
For my problem, I modified the code to be:
ierr = DMDAGetCorners(da,&xs,&ys,PETSC_NULL,&xm,&ym,PETSC_NULL);CHKERRQ(ierr);
for (j=ys; j<ys+ym; j++) {
for (i=xs; i<xs+xm; i++) {
/* Boundary conditions */
if (i == 0 || j == 0 || i == Mx-1 || j == My-1) {
f[j][i] = uarray[j][i];
}
else if (i == 1 || j == 1 || i == Mx-2 || j == My-2) {
f[j][i] = uarray[j][i];
}
else { /* Interior */
u = uarray[j][i];
ux = (uarray[j][i+1] - uarray[j][i-1]);
uy = (uarray[j+1][i] - uarray[j-1][i]);
uxx = (-2.0*u + uarray[j][i-1] + uarray[j][i+1]);
uyy = (-2.0*u + uarray[j-1][i] + uarray[j+1][i]);
uxxx = (uarray[j][i+2] - 2.0*uarray[j][i+1] +
2.0*uarray[j][i-1] - uarray[j][i-2]);
uyyy = (uarray[j+2][i] - 2.0*uarray[j+1][i] +
2.0*uarray[j-1][i] - uarray[j-2][i]);
......
}}}
When I run the executable program, I found:
(1) If I run it on only one process, it is fine.
(2) When using more than one process, I got a error: "[0]PETSC ERROR:
Caught signal number 11 SEGV: Segmentation Violation, probably memory
access out of range"
I am sure that the problem comes out because "uyyy =
(uarray[j+2][i] - 2.0*uarray[j+1][i] + 2.0*uarray[j-1][i] -
uarray[j-2][i]);"
If I discard this sentence, then everything seems OK.
I am wondering, why the above sentence "uxxx=..." can access
"uarray[j][i+2] " succesfully, while the program reports error when
accessing "uarray[j+2][i]" ?
Could anyone give me some advice?
Thanks very much in advance.
Feng-Chao Wang
More information about the petsc-users
mailing list