title: Thread pools with OpenMP: overhead and changing the number of threads
body: <p>I recently discovered the concept of <a href="https://stackoverflow.com/questions/23255821/why-is-openmp-outperforming-pthreads/23285053#23285053">thread pools</a>.  As far as I understand GCC, ICC, and MSVC all use thread pools with OpenMP.  I'm curious to know what happens when I change the number of threads?  For example let's assume the default number of threads is eight.  I create a team of eight threads and then in a later section I do four threads and then I go back to eight.</p>
  
  <pre><code>#pragma omp parallel for
  for(int i=0; i&lt;n; i++)
  
  #pragma omp parallel for num_threads(4)
  for(int i=0; i&lt;n; i++)
  
  #pragma omp parallel for 
  for(int i=0; i&lt;n; i++)
  </code></pre>
  
  <p>This is something I actually do now because part of my code gets worse results with hyper-threading so I lower the number of thread to the number of physical cores (for that part of the code only). What if I did the opposite (4 thread, then eight, then 4)?</p>
  
  <p>Does the thread pool have to be recreated each time I change the number of threads?  If not, does adding or removing threads cause any significant overhead?</p>
  
  <p>What's the overhead for the thread pool, i.e. what fraction of the work per thread goes to the pool?</p>