title: OpenMP Segmentation Fault When Parallelizing Simple Loop
body: <p>I have a function that takes in an array and updates an array in a for loop like such:</p>
  
  <pre><code>void compute(double values[], int num_points, double ders[]){
      for(int i = 0; i &lt; num_points; ++i)
      {
          double a = values[i* 3 + 0 ];
          double b = values[i* 2 + 1 ];
          ders[i*4 + 0] = a * b;
          ders[i*4 + 1] = a * a;
          ders[i*4 + 2] = b * b;
          ders[i*4 + 3] = b * a * a;
     }
  }
  </code></pre>
  
  <p>All of this is well and good but then I update the code to try to do things in parallel with OpenMP like</p>
  
  <pre><code>void compute(double values[], int num_points, double ders[]){
     omp_set_dynamic(0);
     omp_set_num_threads(2);
     #pragma omp parallel for
      for(int i = 0; i &lt; num_points; ++i)
      {
          double a = values[i* 3 + 0 ];
          double b = values[i* 2 + 1 ];
          ders[i*4 + 0] = a * b;
          ders[i*4 + 1] = a * a;
          ders[i*4 + 2] = b * b;
          ders[i*4 + 3] = b * a * a;
     }
  }
  </code></pre>
  
  <p>And now I'm getting Segmentation Faults.</p>
  
  <p>I feel like I must be overwriting some value in two threads -- but everything in ders and values is indexed according to 'i' so it feels like it should be trivial to parallelize.</p>
  
  <p>What am I doing wrong here?</p>