1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include "omp_testsuite.h"
4
5int test_omp_section_private()
6{
7 int sum;
8 int sum0;
9 int i;
10 int known_sum;
11
12 sum = 7;
13 sum0 = 0;
14
15 #pragma omp parallel
16 {
17 #pragma omp sections private(sum0,i)
18 {
19 #pragma omp section
20 {
21 sum0 = 0;
22 for (i = 1; i < 400; i++)
23 sum0 = sum0 + i;
24 #pragma omp critical
25 {
26 sum = sum + sum0;
27 }
28 }
29 #pragma omp section
30 {
31 sum0 = 0;
32 for (i = 400; i < 700; i++)
33 sum0 = sum0 + i;
34 #pragma omp critical
35 {
36 sum = sum + sum0;
37 }
38 }
39 #pragma omp section
40 {
41 sum0 = 0;
42 for (i = 700; i < 1000; i++)
43 sum0 = sum0 + i;
44 #pragma omp critical
45 {
46 sum = sum + sum0;
47 }
48 }
49 } /*end of sections*/
50 } /* end of parallel */
51 known_sum = (999 * 1000) / 2 + 7;
52 return (known_sum == sum);
53} /* end of check_section_private*/
54
55int main()
56{
57 int i;
58 int num_failed=0;
59
60 for(i = 0; i < REPETITIONS; i++) {
61 if(!test_omp_section_private()) {
62 num_failed++;
63 }
64 }
65 return num_failed;
66}
67

source code of openmp/runtime/test/worksharing/sections/omp_section_private.c