Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / runtime / test / barrier / omp_barrier.c
blob052784e0de39764facdea687ee96b231eadefb13
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"
11 int test_omp_barrier()
13 int result1;
14 int result2;
15 result1 = 0;
16 result2 = 0;
18 #pragma omp parallel
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;
26 #pragma omp barrier
27 if (rank == 2) {
28 result1 = result2;
31 return (result1 == 3);
34 int main()
36 int i;
37 int num_failed=0;
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++;
47 #endif
48 return num_failed;