title: Calculate Thread ID in CUDA
body: <p>I write my code, and I use one block of size 8*8. I use this formula to define the index of a matrix:</p>
  
  <pre><code>int idx = blockIdx.x * blockDim.x + threadIdx.x;  
  int idy = blockIdx.y * blockDim.y + threadIdx.y;  
  </code></pre>
  
  <p>And to check it, I put the <code>idx</code> and idy in a 1D array, so I can copy it to host to print it out. </p>
  
  <pre><code>if (idx&lt;N &amp;&amp; idy&lt;N) 
  {
      c[idx]=idx;
      d[idx]=idy;
  }//end if
  </code></pre>
  
  <p>The strange thing is that <code>idy</code> always give me 3!
  Can anyone help to resolve it?</p>