1// RUN: %libomp-compile-and-run
2// critial with hint was introduced with icc 19
3// UNSUPPORTED: icc-18
4
5#include <stdio.h>
6#include <omp.h>
7#include "omp_testsuite.h"
8
9int test_omp_critical(int iter) {
10 int sum;
11 int known_sum;
12
13 sum = 0;
14#pragma omp parallel
15 {
16 int mysum = 0;
17 int i;
18#pragma omp for
19 for (i = 0; i < 1000; i++)
20 mysum = mysum + i;
21
22 switch (iter % 4) {
23 case 0:
24#pragma omp critical(c0) hint(omp_sync_hint_uncontended)
25 sum = mysum + sum;
26 break;
27 case 1:
28#pragma omp critical(c1) hint(omp_sync_hint_contended)
29 sum = mysum + sum;
30 break;
31 case 2:
32#pragma omp critical(c2) hint(omp_sync_hint_nonspeculative)
33 sum = mysum + sum;
34 break;
35 case 3:
36#pragma omp critical(c3) hint(omp_sync_hint_speculative)
37 sum = mysum + sum;
38 break;
39 default:;
40 }
41 }
42 known_sum = 999 * 1000 / 2;
43 return (known_sum == sum);
44}
45
46int main() {
47 int i;
48 int num_failed = 0;
49
50 for (i = 0; i < 4 * REPETITIONS; i++) {
51 if (!test_omp_critical(iter: i)) {
52 num_failed++;
53 }
54 }
55 return num_failed;
56}
57

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