1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include "omp_testsuite.h"
4#include "omp_my_sleep.h"
5
6int test_omp_flush()
7{
8 int result1;
9 int result2;
10 int dummy;
11
12 result1 = 0;
13 result2 = 0;
14
15 #pragma omp parallel
16 {
17 int rank;
18 rank = omp_get_thread_num ();
19 #pragma omp barrier
20 if (rank == 1) {
21 result2 = 3;
22 #pragma omp flush (result2)
23 dummy = result2;
24 }
25 if (rank == 0) {
26 my_sleep(SLEEPTIME);
27 #pragma omp flush (result2)
28 result1 = result2;
29 }
30 } /* end of parallel */
31 return ((result1 == result2) && (result2 == dummy) && (result2 == 3));
32}
33
34int main()
35{
36 int i;
37 int num_failed=0;
38
39 // the test requires more than 1 thread to pass
40 omp_set_dynamic(0); // disable dynamic adjustment of threads
41 if (omp_get_max_threads() == 1)
42 omp_set_num_threads(2); // set 2 threads if no HW resources available
43
44 for (i = 0; i < REPETITIONS; i++) {
45 if(!test_omp_flush()) {
46 num_failed++;
47 }
48 }
49 return num_failed;
50}
51

source code of openmp/runtime/test/flush/omp_flush.c