title: OpenMP - Serialise for-loop in Parallel Region which Contains Parallel for-loop
body: <p>I'm asking a very similar question to <a href="https://stackoverflow.com/questions/30294883/how-to-parallel-for-loop-inside-single-region-in-openmp">this chap</a> but there is only one answer there and it hasn't proved useful for me.</p>
  
  <p>I have a parallel region in <code>main()</code> with a for-loop which calls the function <code>new_value()</code>:</p>
  
  <pre><code>int main(int argc, char** argv)
  {
      omp_set_num_threads(4);
  
  #pragma omp parallel default(shared) private(...)
  {
      for(int i = 0; i &lt; MAX_VALUE; i++)
          new_value(...);
  }
  
      return 0;
  }
  </code></pre>
  
  <p>And <code>new_value()</code> looks like:</p>
  
  <pre><code>void new_value(...)
  {
  #pragma omp for schedule(static, chunk_width)
      for(int i = 0; i &lt; N; i++)
          arr[i] = update();
  }
  </code></pre>
  
  <p>The issue I am having is that I do not want the for-loop in <code>main()</code> to be parallelised (i.e. ran <code>MAX_VALUE * 4</code> times in total).</p>
  
  <p>I essentially want that one loop to be ran serially but the for-loop in <code>new_value()</code> to be ran with four threads.</p>
  
  <p>I tried <code>#pragma omp single</code> before the loop but it caused the program to deadlock or hang on something. I also tried the nested parallelism approach as suggest by the already <a href="https://stackoverflow.com/questions/30294883/how-to-parallel-for-loop-inside-single-region-in-openmp">linked</a> thread but I got the same result.</p>
  
  <p>Any solutions would be appreciated.</p>