title: How do I deal with a data race in OpenMP?
body: <p>I am trying to use OpenMP to add the numbers in an array. The following is my code:</p>
  
  <pre><code>  int* input = (int*) malloc (sizeof(int)*snum);
    int sum = 0;
    int i;
    for(i=0;i&lt;snum;i++){
        input[i] = i+1;
    }
    #pragma omp parallel for schedule(static)
    for(i=0;i&lt;snum;i++)
    {
        int* tmpsum = input+i;
   sum += *tmpsum;
    }
  </code></pre>
  
  <p>This does not produce the right result for <code>sum</code>. What's wrong?</p>