title: OpenMP: Nested parallelism inside three for loops
body: <p>The below code shows sementation fault if I used num_threads(..) and if I try with omp_set_num_threads(..)the following error pops out:<br>
  "<strong>libgomp: Thread creation failed: Resource temporarily unavailable</strong>” 
  The error also arises in case of num_threads (considering the outermost parallel region is removed).</p>
  
  <p><strong>System Specifications:</strong></p>
  
  <ul>
  <li>XEON Processor with 2 sockets, 4 cores/sockets and 16 threads/core </li>
  </ul>
  
  <p><strong>To sum up:</strong>
  I want to have nested parallelism such that outer loops have five threads running parallel and then each thread creates 20 more threads(so in total still less than what my system offers).</p>
  
  <pre><code>void assembly(){ 
      omp_set_nested(1);
      #pragma omp parallel num_threads(5)
      {    //omp_set_num_threads(5);
  
           for (int j=0; j&lt;5; ++j) {
               int itr = nodesInLevel[j];
  
               #pragma omp parallel num_threads(20)
               {// omp_set_num_threads(20);
  
                   #pragma omp for schedule(dynamic) nowait
                   for (int i=0; i&lt;itr; ++i) {
                      int start =tree[j][i]-&gt;cStart[0];
                      int end  = tree[j][i]-&gt;cStart[1];
                      int size0   =tree[j][i]-&gt;cSize[0];
                      int size1   =tree[j][i]-&gt;cSize[1];
                      A-&gt;rook_Piv(start,end,size0,size1,tree[j][i]-&gt;rank[0]);
                   } 
  
                  #pragma omp for //schedule(dynamic) 
                  for (int i=0; i&lt;itr; ++i) {
                     int start =tree[j][i]-&gt;cStart[0];
                     int end  = tree[j][i]-&gt;cStart[1];
                     int size0   =tree[j][i]-&gt;cSize[0];
                     int size1    =tree[j][i]-&gt;cSize[1];
                     A-&gt;rook_Piv(end,start,size1,size0,tree[j][i]-&gt;rank[1]);
                 }
          }
      }
  }
  </code></pre>
  
  <p><strong>Please NOTE:</strong></p>
  
  <p>I know the following code is not described properly but the code was very large and therefore I wasn't able to mention it completely.The problem is not related to code descriton but more to nested parallelism.
  So any suggestions can be helpful. </p>