Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 538903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:04:49+00:00 2026-05-13T10:04:49+00:00

I have a problem I am trying to tackle that involves a 7 point

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:04:49+00:00Added an answer on May 13, 2026 at 10:04 am

    What kind of access pattern is using your 7-point stencil? If you’re having cache coherence problems, this is the first question to ask — if the access pattern of your central (x,y,z) coordinate is completely random, you may be out of luck.

    If you have some control over the access pattern, you can try to adjust it to be more cache-friendly. If not, then you should consider what kind of access pattern to expect; you may be able to arrange the data so that this access pattern is more benign. A combination of these two can sometimes be very effective.

    There is a particular data arrangement that is frequently useful for this kind of thing: bit-interleaved array layout. Assume (for simplicity) that the size of each coordinate is a power of two. Then, a “normal” layout will build the index by concatenating the bits for each coordinate. However, a bit-interleaved layout will allocate bits to each dimension in a round-robin fashion:

    3D index coords: (xxxx, yyyy, zzzz)
    
    normal index:    data[zzzzyyyyxxxx]  (x-coord has least-significant bits, then y)
    bit-interleaved: data[zyxzyxzyxzyx]  (lsb are now relatively local)
    

    Practically speaking, there is a minor cost: instead of multiplying the the coordinates by their step values, you will need to use a lookup table to find your offsets. But since you will probably only need very short lookup tables (especially for a 3D array!), they should all fit nicely into cache.

    3D coords:  (x,y,z)
    
    normal index:      data[x + y*ystep + z*zstep]  where:
      ystep= xsize (possibly aligned-up, if not a power of 2?)
      zsetp= ysize * ystep
    
    bit-interleaved:   data[xtab[x] + ytab[y] + ztab[z]]  where:
      xtab={  0,  1,  8,  9, 64, 65, 72, 73,512...}   (x has bits 0,3,6,9...)
      ytab={  0,  2, 16, 18,128,130,144,146,1024...}  (y has bits 1,4,7,10...)
      ztab={  0,  4, 32, 36,256,260,288,292,2048...}  (y has bits 2,5,8,11...)
    

    Ultimately, whether this is any use depends entirely on the requirements of your algorithm. But, again, please note that if your algorithm is too demanding of your cache, you may want to look into adjusting the algorithm, instead of just the layout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 279k
  • Answers 279k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Take a look at sp_addlinkedserver in Books Online. EXEC sp_addlinkedserver… May 13, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer A sub returns a sub as a coderef: # example… May 13, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer The dynamic proxy is a feature of the JDK. It… May 13, 2026 at 3:20 pm

Related Questions

I am trying to write the HTML and CSS for an internal webapp properly.
I am currently trying to tackle a speed issue involving loading and saving richtext.
I have a C library that needs a callback function to be registered to
I have been trying to tackle this problem , but I am having difficulty
I asked a question about C-type sizes which I get a pretty good answer

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.