Jacobi iterative stencil operation on 3D grid

TA stencil operation is an iterative operation wherein a fixed pattern, called a stencil, is applied to an element in a grid and its surrounding elements.

Being a Jacobi iterative method, the stencil operation takes place over a number of time slices and each element of the grid is updated in each time slice and the algorithm alternates the source and target grids after each iteration.

Code Snippet
#define Index3D(_nx,_ny,_i,_j,_k) ((_i)+_nx*((_j)+_ny*(_k)))

nx = 128;
ny = 128;
nz = 32;
iteration = 100;

for(t = 0; t<iteration; t++){
   for(i = 1; i < nx-1; i++){
      for(j = 1; j < ny-1; j++){
         for(k = 1; k < nz-1; k++){
            Anext[Index3D (nx, ny, i, j, k)] = 
               (A0[Index3D (nx, ny, i, j, k + 1)] +
               A0[Index3D (nx, ny, i, j, k - 1)] +
               A0[Index3D (nx, ny, i, j + 1, k)] +
               A0[Index3D (nx, ny, i, j - 1, k)] +
               A0[Index3D (nx, ny, i + 1, j, k)] +
               A0[Index3D (nx, ny, i - 1, j, k)])*c1
               - A0[Index3D (nx, ny, i, j, k)]*c0;
            }
         }
      }
   }
   float *temp = A0;
   A0 = Anext;
   Anext = temp;
}