1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include "omp_testsuite.h"
4
5int test_omp_critical()
6{
7 int sum;
8 int known_sum;
9
10 sum=0;
11 #pragma omp parallel
12 {
13 int mysum=0;
14 int i;
15 #pragma omp for
16 for (i = 0; i < 1000; i++)
17 mysum = mysum + i;
18
19 #pragma omp critical
20 sum = mysum +sum;
21 }
22 known_sum = 999 * 1000 / 2;
23 return (known_sum == sum);
24}
25
26int main()
27{
28 int i;
29 int num_failed=0;
30
31 for(i = 0; i < REPETITIONS; i++) {
32 if(!test_omp_critical()) {
33 num_failed++;
34 }
35 }
36 return num_failed;
37}
38

source code of openmp/runtime/test/critical/omp_critical.c