1 // RUN: %libomp-compile-and-run
2 #include <stdio.h>
3 #include "omp_testsuite.h"
4 #include "omp_my_sleep.h"
5 
test_omp_barrier()6 int test_omp_barrier()
7 {
8   int result1;
9   int result2;
10   result1 = 0;
11   result2 = 0;
12 
13   #pragma omp parallel
14   {
15     int rank;
16     rank = omp_get_thread_num ();
17     if (rank ==1) {
18       my_sleep(((double)SLEEPTIME)/REPETITIONS); // give 1 sec to whole test
19       result2 = 3;
20     }
21     #pragma omp barrier
22     if (rank == 2) {
23       result1 = result2;
24     }
25   }
26   return (result1 == 3);
27 }
28 
main()29 int main()
30 {
31   int i;
32   int num_failed=0;
33 
34 #ifdef _OPENMP
35   omp_set_dynamic(0); // prevent runtime to change number of threads
36   omp_set_num_threads(4); // the test expects at least 3 threads
37   for(i = 0; i < REPETITIONS; i++) {
38     if(!test_omp_barrier()) {
39       num_failed++;
40     }
41   }
42 #endif
43   return num_failed;
44 }
45