title: OpenMP: "libgomp: Thread creation failed: Resource temporarily unavailable" when code run as regular user
body: <p>When I run the following example code:</p>
  
  <pre><code>#include "stdio.h"
  #include &lt;omp.h&gt;
  
  int main(int argc, char *argv[])
  {
    #pragma omp parallel
    {
     int NCPU,tid,NPR,NTHR;
      /* get the total number of CPUs/cores available for OpenMP */
     NCPU = omp_get_num_procs();
     /* get the current thread ID in the parallel region */
     tid = omp_get_thread_num();
     /* get the total number of threads available in this parallel region */
     NPR = omp_get_num_threads();
     /* get the total number of threads requested */
     NTHR = omp_get_max_threads();
     /* only execute this on the master thread! */
  
     if (tid == 0) {
       printf("%i : NCPU\t= %i\n",tid,NCPU);
       printf("%i : NTHR\t= %i\n",tid,NTHR);
       printf("%i : NPR\t= %i\n",tid,NPR);
     }
     printf("%i : hello multicore user! I am thread %i out of %i\n",tid,tid,NPR);
    }
    return(0);
   }
  </code></pre>
  
  <p>with the command: <code>gcc -fopenmp example.c -o example.exe</code> then <code>./example</code> I get the error: <code>libgomp: Thread creation failed: Resource temporarily unavailable</code> However, when I run this same code and command under <code>sudo</code> I get the expected output:</p>
  
  <pre><code>0 : NCPU    = 4
  0 : NTHR    = 4
  0 : NPR = 4
  2 : hello multicore user! I am thread 2 out of 4
  1 : hello multicore user! I am thread 1 out of 4
  0 : hello multicore user! I am thread 0 out of 4
  3 : hello multicore user! I am thread 3 out of 4
  </code></pre>
  
  <p>Im running Ubuntu 18.04 on x86_64 architecture with 4 cores.</p>
  
  <pre><code>Architecture:        x86_64
  CPU op-mode(s):      32-bit, 64-bit
  Byte Order:          Little Endian
  CPU(s):              4
  On-line CPU(s) list: 0-3
  Thread(s) per core:  2
  Core(s) per socket:  2
  Socket(s):           1
  NUMA node(s):        1
  Vendor ID:           GenuineIntel
  CPU family:          6
  Model:               78
  Model name:          Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
  </code></pre>
  
  <p>I dont really feel comfortable running c code with Openmp as root user. My question is, could someone provide information as to why this may be happening? 
  Thanks</p>