title: problem with finding the minimum index of an array in the shared memory
body: <p>I need to find the minimum index among an array. its easy to do this using one thread but I want to reduce it using parallel threads. </p>
  
  <p>I did it using one thread (if threadIDx.x == 1) ....... and its working fine. but doing this in parallel will increase the efficiency which im looking for.</p>
  
  <p>I wrote this code and it looks logical to me. but when I'm debugging its not picking the minimum value at all !</p>
  
  <p>Code:</p>
  
  <pre><code>#define MIN(x,y) ((x &lt; y) ? x : y)
  #define MIN_IDX(x,y, idx_x, idx_y) ((x &lt; y) ? idx_x : idx_y)
  ....
  ....
  
  
  __shared__ int costs[nt];
  __shared__ int bstids[nt];
  
  int myM = 9999999;
  int mtMId;
  for (int s = nt/2 ; s &gt;= 1 ; s/=2) {
    if (threadIdx.x &lt; s) {
      myM = MIN(costs[threadIdx.x], costs[threadIdx.x+s]);
      costs[threadIdx.x] = myM;
  
      mtMId = MIN_IDX(costs[threadIdx.x], costs[threadIdx.x+s],bstids[threadIdx.x], bstids[threadIdx.x+s]);
      bstids[threadIdx.x] =  mtMId;
      __syncthreads();
  
  }
  }   
  </code></pre>
  
  <p>nt is the number of threads and its a power of 2</p>