1// RUN: %libomp-compile-and-run
2#include "omp_testsuite.h"
3#include <stdlib.h>
4#include <stdio.h>
5
6static int i;
7#pragma omp threadprivate(i)
8
9int test_omp_threadprivate_for()
10{
11 int known_sum;
12 int sum;
13
14 known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
15 sum = 0;
16
17 #pragma omp parallel
18 {
19 int sum0 = 0, i0;
20 #pragma omp for
21 for (i0 = 1; i0 <= LOOPCOUNT; i0++) {
22 i = i0;
23 sum0 = sum0 + i;
24 }
25 #pragma omp critical
26 {
27 sum = sum + sum0;
28 }
29 } /* end of parallel */
30
31 if (known_sum != sum ) {
32 fprintf(stderr, format: " known_sum = %d, sum = %d\n", known_sum, sum);
33 }
34 return (known_sum == sum);
35} /* end of check_threadprivate*/
36
37int main()
38{
39 int i;
40 int num_failed=0;
41
42 for(i = 0; i < REPETITIONS; i++) {
43 if(!test_omp_threadprivate_for()) {
44 num_failed++;
45 }
46 }
47 return num_failed;
48}
49

source code of openmp/runtime/test/threadprivate/omp_threadprivate_for.c