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

source code of openmp/runtime/test/barrier/omp_barrier.c