title: I got omp_get_num_threads always return 1 in gcc (works in icc)
body: <p>I have this old question but no answer works for me from online, the code is:</p>
  
  <pre><code>#include "stdio.h"
  #include "omp.h"
  
  main ()
  {
      omp_set_num_threads(4); //initialise thread count for 4 core cpu                                                                                                                             
      int j;
      printf ("%d\n", omp_get_max_threads());
      printf ("%d\n", omp_get_num_threads());
  #pragma omp parallel for
      for (int j=0; j&lt;10; ++j)
          {
              printf ("%d\n", omp_get_num_threads());
              int threadNum;
              threadNum = omp_get_thread_num();
              printf("This is thread %d\n", threadNum);
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>In G++ 4.4.5, linux 2.6.32-5-amd64, it produces:</p>
  
  <pre><code>4
  1
  1
  This is thread 0
  1
  This is thread 0
  1
  This is thread 0
  1
  This is thread 0
  1
  This is thread 0
  1
  This is thread 0
  1
  This is thread 0
  1
  This is thread 0
  1
  This is thread 0
  1
  This is thread 0
  </code></pre>
  
  <p>If we shift to ICC 12.1.0, it gives me:</p>
  
  <pre><code>4
  1
  4
  This is thread 0
  4
  This is thread 0
  4  
  This is thread 0
  4
  This is thread 1
  4
  This is thread 1
  4
  This is thread 1
  4
  This is thread 2
  4 
  This is thread 2
  4
  This is thread 3
  4
  This is thread 3
  </code></pre>
  
  <p>Any ideas?</p>