xref: /llvm-project/openmp/runtime/test/worksharing/for/omp_parallel_for_if.c (revision 614c7ef81c7de51f61239e609edf9c6716b23ebc)
1 // RUN: %libomp-compile-and-run
2 #include <stdio.h>
3 #include <math.h>
4 #include "omp_testsuite.h"
5 
test_omp_parallel_for_if()6 int test_omp_parallel_for_if()
7 {
8   int known_sum;
9   int num_threads;
10   int sum, sum2;
11   int i;
12   int control;
13 
14   control = 0;
15   num_threads=0;
16   sum = 0;
17   sum2 = 0;
18 
19   #pragma omp parallel for private(i) if (control==1)
20   for (i=0; i <= LOOPCOUNT; i++) {
21     num_threads = omp_get_num_threads();
22     sum = sum + i;
23   }
24 
25   known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
26   fprintf(stderr, "Number of threads determined by"
27     " omp_get_num_threads: %d\n", num_threads);
28   return (known_sum == sum && num_threads == 1);
29 } /* end of check_parallel_for_private */
30 
main()31 int main()
32 {
33   int i;
34   int num_failed=0;
35 
36   for(i = 0; i < REPETITIONS; i++) {
37     if(!test_omp_parallel_for_if()) {
38       num_failed++;
39     }
40   }
41   return num_failed;
42 }
43