[petsc-users] question about DA

Likun Tan likunt at andrew.cmu.edu
Sat Aug 27 15:49:38 CDT 2011


Thanks for your explanation.

I attached my code again, p was used in defining temp and H, when defining
S, we don't need p and zs:

DAGetCorners(da3D, &xs, &ys, &zs, &m, &n, &p);
DAVecGetArray(da3D, Vtemp, &temp);
for(k=zs; k<zs+p; k++) {
   for(j=ys; j<ys+n; j++)  {
       for(i=xs; i<xs+m; i++)  {
          temp[k][j][i]=f(i,j,k); //function evalution
        }
    }
}
DAGetCorners(da3D, &xs, &ys, &zs, &m, &n, &p);
DAVecGetArray(da3D, VH, &H);
for(k=zs; k<zs+p; k++) {
   for(j=ys; j<ys+n; j++)  {
       for(i=xs; i<xs+m; i++)  {
          H[k][j][i]=f(temp); //function evalution
        }
    }
}
DAGetCorners(da2D, &xs, &ys, 0, &m, &n, 0);
DAVecGetArray(da2D, VS, &S);
for(j=ys; j<ys+n; j++)  {
     for(i=xs; i<xs+m; i++)  {
          S[j][i]=g(temp); //function evalution
     }
}


On Sat, August 27, 2011 4:45 pm, Jed Brown wrote:
> On Sat, Aug 27, 2011 at 15:39, Likun Tan <likunt at andrew.cmu.edu> wrote:
>
>
>>
>> I made s simple test,
>>
>>
>> if i assign S[j][i]=temp[2][1][1] for all j, i; it is no problem.
>>
>> while, when assign S[j][i]=temp[2][3][3] for all j, i, it gives me
>> error.
>>
>
> What are m,n,p the first time you call it and what are those values the
> second time?
>
>
>>
>> Your last statement means that i should use temp[j][i][k] if i want to
>> sum over k?
>>
>
> You can't just change the meaning of the indices when you index. Once you
>  fix this problem, feel confident that you understand why, and want to
> make the memory access better for performance, you can look at the calls
> to DMDACreate3d() and the compatible DMDACreate2d() in
> src/snes/examples/tutorials/ex48.c. Also look at the calls to
> DMDAGetCorners() which changes the meaning of x,y,z relative to what
> PETSc
> uses internally.
>
> Unfortunately this can be somewhat error-prone, so you should understand
> why things work the way they do, otherwise it's too easy to get confused.
>






More information about the petsc-users mailing list