[Instrumentation] Fix a warning
[llvm-project.git] / openmp / runtime / test / worksharing / for / omp_for_private.c
blob1f537b90c8f212e9c1249a4a9ab7ccd343fe1fa9
1 // RUN: %libomp-compile-and-run
2 #include <stdio.h>
3 #include <math.h>
4 #include "omp_testsuite.h"
6 /* Utility function do spend some time in a loop */
7 static void do_some_work()
9 int i;
10 double sum = 0;
11 for(i = 0; i < 1000; i++){
12 sum += sqrt ((double) i);
16 int sum1;
17 #pragma omp threadprivate(sum1)
19 int test_omp_for_private()
21 int sum = 0;
22 int sum0;
23 int known_sum;
25 sum0 = 0; /* setting (global) sum0 = 0 */
27 #pragma omp parallel
29 sum1 = 0; /* setting sum1 in each thread to 0 */
30 { /* begin of orphaned block */
31 int i;
32 #pragma omp for private(sum0) schedule(static,1)
33 for (i = 1; i <= LOOPCOUNT; i++) {
34 sum0 = sum1;
35 #pragma omp flush
36 sum0 = sum0 + i;
37 do_some_work ();
38 #pragma omp flush
39 sum1 = sum0;
41 } /* end of orphaned block */
43 #pragma omp critical
45 sum = sum + sum1;
46 } /*end of critical*/
47 } /* end of parallel*/
48 known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
49 return (known_sum == sum);
52 int main()
54 int i;
55 int num_failed=0;
57 for(i = 0; i < REPETITIONS; i++) {
58 if(!test_omp_for_private()) {
59 num_failed++;
62 return num_failed;