title: OpenMP nested loop high performance
body: <p>I have some issues with nested loop in OpenMP (c language). This is what I want to achieve (briefly):</p>
  
  <pre><code>int a=0, b=1000;
  while(a&lt;b) // Not parallel, must run only once.
  {
      for (int i = 0; i &lt; N; ++i) // Must be parallel
      {...}
  
      for (int j = 0; j &lt; N; ++j) // Must be parallel
      {...}
      a++;
  }
  </code></pre>
  
  <p>So I tried thinks like that. But the while loop is execute 4 times:</p>
  
  <pre><code>    int a=0, b=1000;
  omp_set_num_threads(4);
  #pragma parallel omp shared(default)
  {
      while(a&lt;b) // parallel, but run 4 times /!\
      {          // add 'single' doesn't compile. (nested regions)
          #pragma omp for
          for (int i = 0; i &lt; N; ++i) // works well
          {...}
  
          #pragma omp for
          for (int j = 0; j &lt; N; ++j) // works well
          {...}
          a++;
      }
  }
  </code></pre>
  
  <p>So after looking on the web I found this implementation:</p>
  
  <pre><code>    int a=0, b=1000;
  omp_set_num_threads(4);
  #pragma parallel omp shared(default) num_thread(1)
  {
      while(a&lt;b) // parallel and run once
      {
          #pragma parallel omp for num_thread(4)
          for (int i = 0; i &lt; N; ++i) // works well
          {...}
  
          #pragma parallel omp for num_thread(4)
          for (int j = 0; j &lt; N; ++j) // works well
          {...}
          a++;
      }
  }
  </code></pre>
  
  <p>However, this last is slow. It takes 5 to 10 times more time than without OpenMP. So I would like to know if it's possible to avoid declaring parallel region at every step of the while loop? I have already looked at <code>"single"</code> or <code>"master"</code> but those don't allow <code>#pragma</code> regions inside them.</p>