[petsc-users] Accessing array indices in 3D

Barry Smith bsmith at mcs.anl.gov
Tue Nov 30 15:02:55 CST 2010


  Where are you getting these u_localptr arrays? What are you passing in as the Vec into DAVecGetArray()? If you pass in global vectors you CANNOT access ghost points in the arrays (they don't exist) you need to pass in local vectors obtained with DAGetLocalVector() or DACreateLocalVector() to access ghost points.

   Barry


On Nov 30, 2010, at 2:58 PM, khalid ashraf wrote:

> Hi, I am writing the following loop for accessing the vectors in a 3D grid.
> 
>  for (k=zs; k<zs+zm; k++) {
>   for (j=ys; j<ys+ym; j++) {
>   for (i=xs; i<xs+xm; i++) {
>     if (i<(mx-1))
>     {
>     Cx=u_localptr[k][j][i+1]-u_localptr[k][j][i];
>     }
> else
>     {
>     Cx=u_localptr[k][j][i]-u_localptr[k][j][i-1];
>     }
>     if (j<(my-1))
>     {
> //    Cy=v_localptr[k][j+1][i]-v_localptr[k][j][i];
>     Cy=v_localptr[k][j][i]-v_localptr[k][j][i];
>     }
> else
>     {
>     Cy=v_localptr[k][j][i]-v_localptr[k][j-1][i];
>     }
>     if (k<(mz-1))
>     {
> //    Cz=w_localptr[k+1][j][i]-w_localptr[k][j][i];
>     Cz=w_localptr[k][j][i]-w_localptr[k][j][i];
>     }
> else
>     {
>     Cz=w_localptr[k][j][i]-w_localptr[k-1][j][i];
>     }
>       In this code if I uncomment the two commented lines, then the program gives memory access out of range error when run on multiple processors. Could you please tell me what is the problem with the two commented out lines. 
> 
> Thanks.
> 
> Khalid
> 
> 



More information about the petsc-users mailing list