title: CUDA: synchronizing threads
body: <p>Almost anywhere I read about programming with CUDA there is a mention of the importance that all of the threads in a warp do the same thing.<br>
  In my code I have a situation where I can't avoid a certain condition. It looks like this:</p>
  
  <pre><code>// some math code, calculating d1, d2
  if (d1 &lt; 0.5)
  {
      buffer[x1] += 1;  // buffer is in the global memory
  }
  if (d2 &lt; 0.5)
  {
      buffer[x2] += 1;
  }
  // some more math code.
  </code></pre>
  
  <p>Some of the threads might enter into one for the conditions, some might enter into both and other might not enter into either.  </p>
  
  <p>Now in order to make all the thread get back to "doing the same thing" again after the conditions, should I synchronize them after the conditions using  <code>__syncthreads()</code> ? Or does this somehow happens automagically?<br>
  Can two threads be <em>not</em> doing the same thing due to one of them being one operation behind, thus ruining it for everyone? Or is there some behind the scenes effort to get them to do the same thing again after a branch?</p>