title: OpenMP: don't use hyperthreading cores (half `num_threads()` w/ hyperthreading)
body: <p>In <a href="https://stackoverflow.com/questions/36950532/is-openmp-parallel-for-in-g-4-7-not-very-efficient-2-5x-at-5x-cpu">Is OpenMP (parallel for) in g++ 4.7 not very efficient? 2.5x at 5x CPU</a>, I determined that the performance of my programme varies between 11s and 13s (mostly always above 12s, and sometimes as slow as 13.4s) at around 500% CPU when using the default <code>#pragma omp parallel for</code>, and the OpenMP speed up is only 2.5x at 5x CPU w/ <code>g++-4.7 -O3 -fopenmp</code>, on a 4-core 8-thread Xeon.</p>
  
  <p>I tried using <code>schedule(static) num_threads(4)</code>, and noticed that my programme always completes in 11.5s to 11.7s (always below 12s) at about 320% CPU, e.g., runs more consistently, and uses less resources (even if the best run is half a second slower than the rare outlier with hyperthreading).</p>
  
  <p><strong><em>Is there any simple OpenMP-way to detect hyperthreading, and reduce <code>num_threads()</code> to the actual number of CPU cores?</em></strong></p>
  
  <p>(There is a similar question, <a href="https://stackoverflow.com/questions/24368576/poor-performance-due-to-hyper-threading-with-openmp-how-to-bind-threads-to-core">Poor performance due to hyper-threading with OpenMP: how to bind threads to cores</a>, but in my testing, I found that a mere reduction from 8 to 4 threads somehow already does that job w/ g++-4.7 on Debian 7 wheezy and Xeon E3-1240v3, so, this very question is merely about reducing <code>num_threads()</code> to the number of cores.)</p>