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

source code of openmp/runtime/test/parallel/omp_parallel_private.c