title: Different result when Release x64 configuration in VS2015
body: <p>I am implementing a ray tracing program using VS2015 community. The program fills a screen size color buffer (<code>width * height</code> with element type of <code>Eigen::Vector3f</code>), then save the buffer content to a ppm file.</p>
  
  <p>The basic loop (Note the output section at the end of the outer loop):</p>
  
  <pre><code>using Vec3f = Eigen::Vector3f;
  
  Vec3f * buffer = new Vec3f[w * h];
  
  // for each pixel
  for (int y = 0; y &lt; h; y++) for (int x = 0; x &lt; w; x++) 
  {
      int const i = (h - y - 1) * w + x;
      buffer[i] = Vec3f::Zero();
  
      // 2x2 subpixel 
      for (int sy = 0; sy &lt; 2; sy++) for (int sx = 0; sx &lt; 2; sx++)
      {
          Vec3f r = Vec3f::Zero();
  
          // sampling
          for (int s = 0; s &lt; samps; s++) 
          {
              // do some computation and accumulation to r
              // r = ...
          }
          buffer[i] = buffer[i] + r;
      }
      buffer[i] = buffer[i] * 0.25f;
  
      // debug with an output section
      //if (x % 16 == 0 &amp;&amp; y % 16 == 0)
      //  std::cout &lt;&lt; buffer[i] &lt;&lt; std::endl;
  
  }
  </code></pre>
  
  <p>I can get proper result with configurations of:</p>
  
  <ul>
  <li>Debug, x86 or x64; </li>
  <li>Release, x86;</li>
  <li>Release (optimization = \Od), x64.</li>
  </ul>
  
  <p>However, the buffer is all zero vectors with <strong>Release (optimization = \O1 or \O2 or \Ox), x64</strong>, and what I got is a black picture. </p>
  
  <p>So with <strong>Release (optimization = \O1 or \O2 or \Ox), x64</strong>, I uncommented the output section to check the values in the buffer. The strange thing is, each pixel that I checked has a correct value, those not checked remains zero vector. For example, if I check every 16 pixels like the upper code, I will get a picture like this (256*256 black tessellated every 16 pixel):</p>
  
  <p><a href="https://i.stack.imgur.com/suCYa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/suCYa.png" alt="wrong answer with Release optimization=\O1 x64"></a></p>
  
  <p>I googled and read some materials like <a href="http://www.codeproject.com/Articles/548/Surviving-the-Release-Version" rel="nofollow noreferrer">Surviving the Release Version</a>, but still have no idea. Could anyone provide some experiences dealing with these problems?</p>
  
  <p><strong>Update</strong>: The code above is not so detailed, full code is <a href="https://ideone.com/C3t5Db" rel="nofollow noreferrer">here</a>, depends on Eigen 3.2.6. </p>