I have a problem I am trying to tackle that involves a 7 point computational stencil. For those who may not know, this would be a 3D grid, and the 7 points are the n th point, and the neighbors one point away in the x, y and z directions, both positive and negative (or neighbors to the east/west/north/south and up/down).
So these 6 points plus the 1 additional point i am working on are used in a calculation, and are all stored in a 1 dimensional array.
Assume nx is the width of the cube, and ny is the height. In memory, then, when I am accessing a point in the array All_Points, such as All_points[n], then to get it s neighbors in each direction, I also want to access All_points[n-1], All_points[n+1], All_points[n-nx], All_points[n+nx], All_points[n-nxny], and All_points[n+nxny].
So my problem with this is that I am getting a ton of cache misses. I can t seem to find any code example that demonstrate how to avoid This problem. Ideally I d like to split this array back up into it s x, y and z coordinates, such as All_x_points[] but then I run into a problem trying to keep that updated, since All_points[n] changes, and when it does, that means for some other All_points[n ] my x, y or z value will need to be updated with it.
Anyone seen this kind of thing done before?