Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that you have a lot of opportunities to optimize your code. Your x loop executes 128 times, your y loop executes 128*128=16,384 times, and your z loop executes 128^3=2,097,152 times. There are a number of terms inside your z loop that are only dependent on the x, or the y iterations, but they are recalculated at every z iteration. For example, </p> <pre><code>int poxox = plusOffsetX - offsetX; </code></pre> <p>and </p> <pre><code>double poxxpoxox = ((plusOffsetX - x) / (double)poxox); </code></pre> <p>These two terms are being calculated more than 2 million times, but only need to be calculated 128 times if my cursory scan of your function is correct. Move terms to the loop level that is appropriate so you don't waste cycles recalculating the same values many multiple times.</p> <p>Here is your code with basic optimizations made. I'm curious to know how this affects your run times. Several of the terms are only dependent on the iteration value, and are the same for x, y, and z. So I pulled them out entirely and precompute them once. I also have moved the outer mod operations out of the inner loop, and modified the logic to ensure short circuit of the evaluation, which should should remove the majority of mod operations that were previously being executed.</p> <pre><code>int[] offsets = new int[128]; int[] plusOffsets = new int[128]; double[] poii = new double[128]; double[] ioip = new double[128]; for (int i = 0; i &lt; 128; i++) { offsets[i] = (i / SAMPLE_RATE_3D_HOR) * SAMPLE_RATE_3D_HOR; plusOffsets[i] = SAMPLE_RATE_3D_HOR + offsets[i]; double poioi = (double) (plusOffsets[i] - offsets[i]); poii[i] = ((plusOffsets[i] - i) / poioi); ioip[i] = ((i - offsets[i]) / poioi); } float[, ,] DensityMap = new float[128, 128, 128]; float[, ,] PressureMap = new float[128, 128, 128]; for (int x = 0; x &lt; g_CraftWorldConstants.RegionSizeX; x++) { int offsetX = offsets[x]; int plusOffsetX = plusOffsets[x]; double poxxpoxox = poii[x]; double xoxpoxox = ioip[x]; bool xModNot0 = !(x % SAMPLE_RATE_3D_HOR == 0); for (int y = 0; y &lt; g_CraftWorldConstants.RegionSizeY; y++) { int offsetY = offsets[y]; int plusOffsetY = plusOffsets[y]; double poyypoyoy = poii[y]; double yoypoyoy = ioip[y]; bool yModNot0 = !(y % SAMPLE_RATE_3D_VERT == 0); for (int z = 0; z &lt; g_CraftWorldConstants.RegionSizeZ; z++) { //if (!(x % SAMPLE_RATE_3D_HOR == 0 &amp;&amp; y % SAMPLE_RATE_3D_VERT == 0 &amp;&amp; z % SAMPLE_RATE_3D_HOR == 0)) if (xModNot0 || yModNot0 || !(z % SAMPLE_RATE_3D_HOR == 0)) { int offsetZ = offsets[z]; int plusOffsetZ = plusOffsets[z]; double pozzpozoz = poii[z]; double zozpozoz = ioip[z]; double x00 = poxxpoxox * DensityMap[offsetX, offsetY, offsetZ] + xoxpoxox * DensityMap[plusOffsetX, offsetY, offsetZ]; double x10 = poxxpoxox * DensityMap[offsetX, offsetY, plusOffsetZ] + xoxpoxox * DensityMap[plusOffsetX, offsetY, plusOffsetZ]; double x01 = poxxpoxox * DensityMap[offsetX, plusOffsetY, offsetZ] + xoxpoxox * DensityMap[plusOffsetX, plusOffsetY, offsetZ]; double x11 = poxxpoxox * DensityMap[offsetX, plusOffsetY, plusOffsetZ] + xoxpoxox * DensityMap[plusOffsetX, plusOffsetY, plusOffsetZ]; double r0 = poyypoyoy * x00 + yoypoyoy * x01; double r1 = poyypoyoy * x10 + yoypoyoy * x11; DensityMap[x, y, z] = (float)(pozzpozoz * r0 + zozpozoz * r1); double x02 = poxxpoxox * PressureMap[offsetX, offsetY, offsetZ] + xoxpoxox * PressureMap[plusOffsetX, offsetY, offsetZ]; double x12 = poxxpoxox * PressureMap[offsetX, offsetY, plusOffsetZ] + xoxpoxox * PressureMap[plusOffsetX, offsetY, plusOffsetZ]; double x03 = poxxpoxox * PressureMap[offsetX, plusOffsetY, offsetZ] + xoxpoxox * PressureMap[plusOffsetX, plusOffsetY, offsetZ]; double x13 = poxxpoxox * PressureMap[offsetX, plusOffsetY, plusOffsetZ] + xoxpoxox * PressureMap[plusOffsetX, plusOffsetY, plusOffsetZ]; double r2 = poyypoyoy * x02 + yoypoyoy * x03; double r3 = poyypoyoy * x12 + yoypoyoy * x13; PressureMap[x, y, z] = (float)(pozzpozoz * r2 + zozpozoz * r3); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload