title: Finding max value in CUDA
body: <p>I am trying to write a code in CUDA for finding the max value 
  for the given set of  numbers.</p>
  
  <p>Assume you have 20 numbers, and the kernel is running on 2 blocks of 5 threads. Now assume the 10 threads compare the first 10 values at the same time, and <strong>thread 2</strong> finds a max value, so thread 2 is updating the max value variable in global memory. While thread 2 is updating, what will happen to the remaining threads (1,3-10) that will be comparing using the old value?</p>
  
  <p>If I lock the global variable using atomicCAS(), will the threads (1,3-10) compare using the old max value? How can I overcome this problem?</p>