title: CUDA finding the max value in given array
body: <p>I tried to develop a small CUDA program for find the max value in the given array,</p>
  
  <pre><code>int input_data[0...50] = 1,2,3,4,5....,50
  </code></pre>
  
  <p><code>max_value</code> initialized by the first value of the <code>input_data[0]</code>,
  The final answer is stored in <code>result[0]</code>. 
  The kernel is giving 0 as the max value. I don't know what the problem is.
  I executed by 1 block 50 threads.</p>
  
  <pre><code>__device__ int lock=0;
  
  __global__ void max(float *input_data,float *result)
  {
       float max_value = input_data[0];
       int  tid = threadIdx.x;
  
       if( input_data[tid] &gt; max_value)
       {
           do{} while(atomicCAS(&amp;lock,0,1));
           max_value=input_data[tid];
           __threadfence();
           lock=0;
        }
  
      __syncthreads();
      result[0]=max_value;  //Final result of max value 
  }
  </code></pre>
  
  <p>Even though there are in-built functions, just I am practicing small problems. </p>