title: Doing a section with one thread and a for-loop with multiple threads
body: <p>I am using OpenMP and I want to spawn threads such that one thread executes one piece of code and finishes, in parallel with N threads running the iterations of a parallel-for loop.</p>
  
  <p>Execution should be like this:</p>
  
  <pre><code>Section A (one thread)       ||      Section B (parallel-for, multiple threads)
           |                   ||        | | | | | | | | | |
           |                   ||        | | | | | | | | | |
           |                   ||        | | | | | | | | | |
           |                   ||        | | | | | | | | | |
           |                   ||        | | | | | | | | | |
           V                   ||        V V V V V V V V V V
  </code></pre>
  
  <p>I cannot just write a parallel-for with a <code>#pragma omp once</code> because I do not want the thread that executes section A to execute the for-loop.</p>
  
  <p>I have tried this:</p>
  
  <pre><code>#pragma omp parallel sections {
      #pragma omp section
      {
           // Section A
      }
  
      #pragma omp section
      {
           // Section B;
           #pragma omp parallel for
           for (int i = 0; i &lt; x; ++i)
               something();
      }
  }
  </code></pre>
  
  <p>However, the parallel-for always executes with only one thread (I know because I made the body of the loop print <code>omp_get_thread_num()</code> and they are all the same number, either 1 or 0 depending on which thread of the two executed the second parallel section).</p>
  
  <p>I have also tried</p>
  
  <pre><code>#pragma omp sections {
      #pragma omp section
      {
           // Section A
      }
  
      #pragma omp section
      {
           // Section B;
           #pragma omp parallel for
           for (int i = 0; i &lt; x; ++i)
               something();
      }
  }
  </code></pre>
  
  <p>Which allows the for-loop to execute with multiple threads, but it makes the sections non-parallel, and the first section is executed sequentially before the second section.</p>
  
  <p>What I need is a combination of the two approaches, where each iteration of the for-loop and the first section are all run in parallel.</p>