title: How do I set the number of threads in OpenMP
body: <p>I am trying to set the number of threads within a program using OpenMP. For some reason, even though the maximum number of threads is 4, my program only uses 1 core. I'm on MacOSX but I'm using the gcc compiler (specifically: gcc9.1.0 and OpenMP version 4.5)</p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;chrono&gt;
  
  #include &lt;omp.h&gt;
  
  int main() {
    int maxthreads = omp_get_max_threads();
  
    std::cout &lt;&lt; "maxthreads: " &lt;&lt; maxthreads &lt;&lt; std::endl;
  
    omp_set_dynamic(0);
    omp_set_num_threads(4);
    #pragma omp parallel num_threads(4)
    {
       int id = omp_get_thread_num();
       #pragma omp critical
       std::cout &lt;&lt; "Hi from " &lt;&lt; id &lt;&lt; std::endl;
    }
  }
  </code></pre>
  
  <p>The result that I get is:</p>
  
  <pre><code>4
  Hi from 0
  </code></pre>
  
  <p>But I expected "Hi from i" to be printed 4 times.</p>