title: OpenMP while loop inside parallel
body: <p>//</p>
  
  <p>EDIT: How do i make 5 threads run code A and the 6th thread run code B CONCURRENTLY then pass their result into a single thread after ALL threads have their code ? I read that im not allowed to use the keyword barrier <a href="https://stackoverflow.com/questions/4771501/openmp-threads-disobey-omp-barrier">OpenMP threads &quot;disobey&quot; omp barrier</a></p>
  
  <p>This was my original code</p>
  
  <pre><code>omp_set_num_threads(6);
  #pragma omp parallel
      {
          int TID = omp_get_thread_num();
  
          while (true)
          {
              if (TID &lt; 5)
              {
                  // codeA
  
              }
  
              else
              {
                  // codeB
              }
  
              // combine result from A and B
              #pragma single
              {
                  //show result A and B
              }
          }
      }
  </code></pre>
  
  <p>I might have found a solution after googling enough <a href="https://stackoverflow.com/questions/7322960/can-i-assign-multiple-threads-to-a-code-section-in-openmp">Can I assign multiple threads to a code section in OpenMP?</a></p>
  
  <p>I should be able to set 5 threads to do task A and 1 thread to do task B. I just gotta use critical before exiting the 5 threads to accumulate the results.</p>