title: OpenCL float sum reduction
body: <p>I would like to apply a reduce on this piece of my kernel code (1 dimensional data):</p>
  
  <pre><code>__local float sum = 0;
  int i;
  for(i = 0; i &lt; length; i++)
    sum += //some operation depending on i here;
  </code></pre>
  
  <p>Instead of having just 1 thread that performs this operation, I would like to have n threads (with n = length) and at the end having 1 thread to make the total sum.</p>
  
  <p>In pseudo code, I would like to able to write something like this:</p>
  
  <pre><code>int i = get_global_id(0);
  __local float sum = 0;
  sum += //some operation depending on i here;
  barrier(CLK_LOCAL_MEM_FENCE);
  if(i == 0)
    res = sum;
  </code></pre>
  
  <p>Is there a way?</p>
  
  <p>I have a race condition on sum.</p>