Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / runtime / test / threadprivate / omp_threadprivate_for.c
blob3342e634276302a275b82e89bf16adf5c79dca23
1 // RUN: %libomp-compile-and-run
2 #include "omp_testsuite.h"
3 #include <stdlib.h>
4 #include <stdio.h>
6 static int i;
7 #pragma omp threadprivate(i)
9 int test_omp_threadprivate_for()
11 int known_sum;
12 int sum;
14 known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
15 sum = 0;
17 #pragma omp parallel
19 int sum0 = 0, i0;
20 #pragma omp for
21 for (i0 = 1; i0 <= LOOPCOUNT; i0++) {
22 i = i0;
23 sum0 = sum0 + i;
25 #pragma omp critical
27 sum = sum + sum0;
29 } /* end of parallel */
31 if (known_sum != sum ) {
32 fprintf(stderr, " known_sum = %d, sum = %d\n", known_sum, sum);
34 return (known_sum == sum);
35 } /* end of check_threadprivate*/
37 int main()
39 int i;
40 int num_failed=0;
42 for(i = 0; i < REPETITIONS; i++) {
43 if(!test_omp_threadprivate_for()) {
44 num_failed++;
47 return num_failed;