title: OpenMP set_num_threads() is not working
body: <p>I am writing a parallel program using OpenMP in C++.</p>
  
  <p>I want to control the number of threads in the program using <code>omp_set_num_threads()</code>, but it does not work.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;omp.h&gt;
  #include "mpi.h"
  
  using namespace std;
  
  int myrank;
  int groupsize;
  double sum;
  double t1,t2;
  int n = 10000000;
  
  int main(int argc, char *argv[])
  {
      MPI_Init( &amp;argc, &amp;argv);
      MPI_Comm_rank( MPI_COMM_WORLD, &amp;myrank );
      MPI_Comm_size(MPI_COMM_WORLD,&amp;groupsize);
  
      omp_set_num_threads(4);
  
      sum = 0;
      #pragma omp for  reduction(+:sum)
      for (int i = 0; i &lt; n; i++)
          sum+= i/(n/10);
  
      cout&lt;&lt;"sum="&lt;&lt;sum&lt;&lt;endl;
      cout&lt;&lt;"threads="&lt;&lt;omp_get_num_threads()&lt;&lt;endl;
  
      MPI_Finalize();
      return 0;
  }
  </code></pre>
  
  <p>The program outputs:</p>
  
  <pre><code>sum = 4.5e+007
  threads=1
  </code></pre>
  
  <p>How to control the number of threads?</p>