title: How to make sum calculations without using atomic in CUDA
body: <p>In the below code, how can I calculate <strong>sum_array</strong> value without using <em>atomicAdd</em>.</p>
  
  <p>Kernel method</p>
  
  <pre><code>__global__ void calculate_sum( int width,
                                 int height,
                                 int *pntrs,
                                 int2 *sum_array )
  {
      int row = blockIdx.y * blockDim.y + threadIdx.y;
      int col = blockIdx.x * blockDim.x + threadIdx.x;
  
      if ( row &gt;= height || col &gt;= width ) return;
  
      int idx = pntrs[ row * width + col ];
  
      //atomicAdd( &amp;sum_array[ idx ].x, col );
  
      //atomicAdd( &amp;sum_array[ idx ].y, row );
  
      sum_array[ idx ].x += col;
  
      sum_array[ idx ].y += row;
  }
  </code></pre>
  
  <p>Launch Kernel</p>
  
  <pre><code>    dim3 dimBlock( 16, 16 );
      dim3 dimGrid( ( width + ( dimBlock.x - 1 ) ) / dimBlock.x, 
                    ( height + ( dimBlock.y - 1 ) ) / dimBlock.y );
  </code></pre>