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

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