title: OpenMP taskloop inside task
body: <p>I am using the OpenMP <code>taskloop</code> construct inside a <code>task</code> construct:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>double compute(int input) {
    int array[4] = {0};
    double value = input;
  
    #pragma omp taskloop private(value)
    for(int i=0; i&lt;5000000; i++) {                                                                                                       
      // random computation, the result is not meaningful
      value *= std::tgamma(std::exp(std::cos(std::sin(value)*std::cos(value))));
      int tid = omp_get_thread_num();
      array[tid] ++;
    }
  
    for(int i=0; i&lt;4; i++) {
      printf("array[%d] = %d ", i, array[i]);
    }
    printf("\n");
  
    return value;
  }
  
  int main (int argc, char *argv[]) {
    omp_set_nested(1);
    omp_set_num_threads(4);  // 4 cores on my machine
  
    #pragma omp parallel 
    {
      #pragma omp single
      {
        #pragma omp task
        { compute(omp_get_thread_num()); }
      }
    }                                                                                                     
   }
  </code></pre>
  
  <p>The resulting array is all 0. However, if I change the <code>taskloop</code> to <code>parallel for</code>:</p>
  
  <pre><code>  #pragma omp parallel for private(value)
    for(int i=0; i&lt;5000000; i++) {
      value *= std::tgamma(std::exp(std::cos(std::sin(value)*std::cos(value))));
      int tid = omp_get_thread_num();
      array[tid] ++; 
    }
  
  </code></pre>
  
  <p>Then the result of the array is 1250000 for each index. Is there anything wrong in my use of <code>taskloop</code> construct?</p>