1 // RUN: %libomp-compile-and-run
2 #include <stdio.h>
3 #include "omp_testsuite.h"
4 #include "omp_my_sleep.h"
5 
6 int 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 
34 int main()
35 {
36   int i;
37   int num_failed=0;
38 
39   for (i = 0; i < REPETITIONS; i++) {
40     if(!test_omp_flush()) {
41       num_failed++;
42     }
43   }
44   return num_failed;
45 }
46