OpenMP 並行區域中的條件子句

#include <omp.h>
#include <stdio.h>

int main (void)
{
  int t = (0 == 0); // true value
  int f = (1 == 0); // false value

  #pragma omp parallel if (f)
  { printf ("FALSE: I am thread %d\n", omp_get_thread_num()); }

  #pragma omp parallel if (t)
  { printf ("TRUE : I am thread %d\n", omp_get_thread_num()); }

  return 0;
}

它的輸出是:

$ OMP_NUM_THREADS=4 ./test
FALSE: I am thread 0
TRUE : I am thread 0
TRUE : I am thread 1
TRUE : I am thread 3
TRUE : I am thread 2