title: C++ AMP, for loops to parallel_for_each loop
body: <p>I'm converting an algorithm to make use of the massive acceleration that C++ AMP provides. The stage I'm at is putting the for loops into the known parallel_for_each loop.</p>
  
  <p>Normally this should be a straightforward task to do but it appears more complex then I first thought. It's a nested loop which I increment using steps of 4 per iterations:</p>
  
  <pre><code>for(int j = 0; j &lt; height; j += 4, data += width * 4 * 4)
  {
      for(int i = 0; i &lt; width; i += 4)
      {
  </code></pre>
  
  <p>The trouble I'm having is the use of the index. I can't seem to find a way to properly fit this into the parallel_for_each loop. Using an index of rank 2 is the way to go but manipulating it via branching will do harm to the performance gain.</p>
  
  <p>I found a similar post: <a href="https://stackoverflow.com/questions/8853894/controlling-the-index-variables-in-c-amp">Controlling the index variables in C++ AMP</a>. It also deals about index manipulation but the increment aspect doesn't cover my issue.</p>
  
  <p>With kind regards,</p>
  
  <p>Forcecast</p>