Time performance when permuting and casting double to float

后端 未结 3 1597
花落未央
花落未央 2021-01-05 07:39

I have some big arrays given by MATLAB to C++ (therefore I need to take them as they are) that needs casting and permuting (row-mayor, column mayor issues).

The arr

3条回答
  •  感动是毒
    2021-01-05 07:41

    In terms of the algorithm you're using, I think you're always going to end up with three nested loops.

    Two things to think about:

    • In your innermost loop, there's some values that you calculate every time, which don't change every iteration. The compiler may cache them, but maybe not, so try moving them to the highest possible scope.
      • k * size_proj[1]
      • i * size_proj[1]
      • size_proj[0] * size_proj[1] (and j * size_proj[0] * size_proj[1] is used twice)
    • Think about how your arrays are laid out in memory. Is there a way you can reorder your loops so that you're reading and writing to continuous regions of memory as much as possible? You'll get fewer cache misses and better performance if you read and write to continuous regions.

提交回复
热议问题