title: OpenCL find max in array
body: <p>I am trying to find max value in a 1-D array by reduction operators. I had refered the method in: <a href="http://developer.amd.com/resources/documentation-articles/articles-whitepapers/opencl-optimization-case-study-simple-reductions/" rel="nofollow">OpenCL™ Optimization Case Study: Simple Reductions</a> </p>
  
  <p>Following is my code:</p>
  
  <pre><code>    __kernel void Normallize(__global float* input, __global float* output,__global float* cmax, int rows, int cols){
  
      int g_idx = get_global_id(0);
  
      for(int i=0 ; i&lt; get_global_size(0) ; i++) cmax[i] = 0;
  
      barrier(CLK_GLOBAL_MEM_FENCE);
  
      for(int offset =  get_global_size(0)/2 ; offset &gt;0 ; offset--){
          if(g_idx &lt; offset){
              float pre = input[g_idx];
              float next = input[g_idx + offset];
              cmax[g_idx] = (pre &gt; next) ? pre:next;
          }
          barrier(CLK_GLOBAL_MEM_FENCE);
      }
  
     output[g_idx] = cmax[0];
  }
  </code></pre>
  
  <p>After do some research, I still can't figure out the problem in my code.</p>