[Instrumentation] Fix a warning
[llvm-project.git] / openmp / runtime / test / tasking / omp_task_private.c
blob7a93716de12f3d447dbca05fa23b1e235b35e5df
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 int test_omp_task_private()
9 int i;
10 int known_sum;
11 int sum = 0;
12 int result = 0; /* counts the wrong sums from tasks */
14 known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
16 #pragma omp parallel
18 #pragma omp single
20 for (i = 0; i < NUM_TASKS; i++) {
21 #pragma omp task private(sum) shared(result, known_sum)
23 int j;
24 //if sum is private, initialize to 0
25 sum = 0;
26 for (j = 0; j <= LOOPCOUNT; j++) {
27 #pragma omp flush
28 sum += j;
30 /* check if calculated sum was right */
31 if (sum != known_sum) {
32 #pragma omp critical
33 result++;
35 } /* end of omp task */
36 } /* end of for */
37 } /* end of single */
38 } /* end of parallel*/
39 return (result == 0);
42 int main()
44 int i;
45 int num_failed=0;
47 for(i = 0; i < REPETITIONS; i++) {
48 if(!test_omp_task_private()) {
49 num_failed++;
52 return num_failed;