title: Parallel for loop for addition of local matrices in OpenMP
body: <p>I have n local copies of matrices,say 'local', in n threads. I want to update a global shared matrix 's' with its elements being sum of corresponding elements of all local matrices. 
  For eg. s[0][0] = local_1[0][0] + local_2[0][0]+...+local_n[0][0].</p>
  
  <p>I wrote the following loop to achieve it - </p>
  
  <pre><code>#pragma omp parallel for
  for(int i=0;i&lt;rows;i++)
  {   
      for(int j=0;j&lt;cols;j++)
          s[i][j]=s[i][j]+local[i][j];
  }  
  </code></pre>
  
  <p>This doesn't seem to work. Could someone kindly point out where am I going wrong?</p>
  
  <p>Updated with example - </p>
  
  <p>Suppose there are 3 threads, with following local matrices - </p>
  
  <pre>
  
  <b>thread 1</b>
  local =  1  2
           3  4
  
  <b>thread 2 </b>
  local =  5  6 
           7  8
  
  <b>thread 3 </b>
  local =  1  0
           0  1
  
  shared matrix would then be 
  
  s     =  7  8 
          10 13
  </pre>