title: CUDA find sum of elements of the array
body: <p>hello I want to find the sum of array elements using CUDA.</p>
  
  <pre><code>__global__ void countZeros(int *d_A, int * B)
  {
      int index = blockIdx.x * blockDim.x + threadIdx.x;
      B[0] = B[0]+d_A[index];
  }
  </code></pre>
  
  <p>so in the end, B[0] supposed to contain the sum of all elements. but I noticed that B[0] equals to zero every time. so in the end it contains only last element.
  why B[0] becomes zero every time?</p>