Calculations with subgrid of megagrid


Dear all!

I am currently working on a C++ algorithm for my study.

I have a 512^3 grid of booleans. I need to reduce this to a 64^3 double grid.

This is demanding a lot computationally. Therefore I am wondering what would be the best approach.

For the calculation of 1 pixel in the 64^3 grid I need a 32^3 part of the 512^3 grid.

I now copy the part needed to a 32^3 grid and give that as an argument to a function. But wouldn't it be more efficient to not make a copy of a part of the 512^3 grid but just make a 32^3 grid of references? Or would that be unefficient because the values of the 32^3 grid are stored unstructured (with large gaps) in the memory of the 512^3 grid.

I hope you understand my question and can help me.

Thank you very much.

With kind regards,
Jasper Levink
Actually, you've completely lost me. Other than the fact that you are using vast amounts of memory for a potentially sparse matrix that has something to do with pixels...

Please specify exactly what you are trying to accomplish.

References are always more efficient than copies, assuming that the object being copied doesn't have copy-on-write powers and/or other shallow-vs-deep-copy powers built-in.
I'll try again :)

I have a huge grid of voxels, 512^3.

64^3 times I take a part of this grid for calculations (in this case a weighted summation, but that isn't really important i think). This subpart is a 32^3 part of the 512^3 grid.

so:
double grid[512][512][512];
for(64^3 times)
calcIntegral(takeSubGrid(grid))


calcIntegral(double subGrid[32][32][32]) will result in a double and takeSubGrid(double grid[512][512][512]) will result the subpart of the grid.

All of these 64^3 times, the subgrid will be different.

My question is:
Should the function takeSubGrid copy a part of the 512^3 grid? Or should it return a list of references?

Advantage of giving references in my opinion: more efficient then copying
disadvantage: The 512^3 grid is stored in memory whith high structure. However the values of the subgrid will be randomly spread over memory when using references. Making calculations less efficient.

memory of 512^3 grid:

value000001
value000002
value000003
value000004 -> used in subgrid
value000005
value000006
value000007
value000008
value000009 -> used in subgrid
value000010
...

If i would copy the subgrid to a new location in the memory it will be very structured:
value000004
value000009
value000023
value000035
value000040
...

What would be the biggest efect? The loss in time by not copying or the time saving due to the high structure of the subgrid in the memory when copying.

I hope things got a little more clear...

Thanks.
Jasper

Topic archived. No new replies allowed.