title: How to process return in OpenMP parallel code?
body: <p>My requirement is like this: every thread allocates memory itself, then processes it:  </p>
  
  <pre><code>typedef struct
  {
      ......
  }A;
  
  A *p[N];
  
  #pragma omp parallel
  {
      #pragma omp for
      for (int i = 0; i &lt; N; i++) {
          p[i] = (A*)calloc(sizeof(*p[i]), N);
          if (NULL == p[i]) {
              return;
          }
          ......          
      }
  }
  </code></pre>
  
  <p>But the compiler will complain:  </p>
  
  <pre><code>error: invalid exit from OpenMP structured block
       return;
  </code></pre>
  
  <p>So except put the allocating memory code out of the <code>#pragma omp parallel</code>:  </p>
  
  <pre><code>for (int i = 0; i &lt; N; i++) {
      p[i] = (A*)calloc(sizeof(*p[i]), N);
      if (NULL == p[i]) {
          return;
      }       
  }
  #pragma omp parallel
  {
      #pragma omp for
      ......
  }
  </code></pre>
  
  <p>Is there any better method?</p>