omp_get_num_threads() and omp_get_thread_num() returning nonsense
<p>I am just starting out with using OpenMP in Fortran using the Intel Fortran compiler and Visual Studio 2015. In the project properties I have "Fortran -> Language -> Process OpenMP Directives" set to "Generate Parallel Code (/Qopenmp)"</p>

<p>I have a simple program starting as follows:</p>

<pre><code>program hellothreads
   integer threads, id
   call omp_set_num_threads(3)   
   threads = omp_get_num_threads()

   print *,"there are",  threads, "threads"
</code></pre>

<p>This produces</p>

<blockquote>
  <p>there are -2147483648 threads</p>
</blockquote>

<p>which there certainly aren't. Setting the number of threads seems to work OK though, since:</p>

<pre><code>   !$OMP Parallel private(id) shared(threads)
   threads = omp_get_num_threads()
   id = omp_get_thread_num()
   print *, "hello from thread", id, "out of", threads
   !$OMP end Parallel
</code></pre>

<p>outputs</p>

<blockquote>
  <p>hello from thread -2147483648 out of -2147483648</p>
  
  <p>hello from thread -2147483648 out of -2147483648</p>
  
  <p>hello from thread -2147483648 out of -2147483648   </p>
</blockquote>

<p>and continuing with:</p>

<pre><code>   !$OMP Parallel private(id) shared(threads)
   threads = omp_get_num_threads()
   id = omp_get_thread_num()
   print *, "this is thread", id, "of", threads
   !$OMP end Parallel
</code></pre>

<p>outputs</p>

<blockquote>
  <p>this is thread -2147483648 of -2147483648</p>
  
  <p>this is thread -2147483648 of -2147483648</p>
</blockquote>

<p>Finally there is <em>different</em> weird behaviour if I call the OpenMP functions inside the a "print": e.g.:  </p>

<pre><code>   !$OMP Parallel private(id) shared(threads)
   print *, "this is thread", omp_get_num_threads(), "of", omp_get_thread_num()
   !$OMP end Parallel
   stop
end
</code></pre>

<p>Outputs</p>

<blockquote>
  <p>this is thread            NaN of            NaN</p>
  
  <p>this is thread            NaN of            NaN</p>
</blockquote>

<p>What is wrong with my configuration and/or code?</p>