Jonathan Peyton | 614c7ef | 2015-09-21 20:41:31 +0000 | [diff] [blame] | 1 | // RUN: %libomp-compile-and-run |
| 2 | #include <stdio.h> |
| 3 | #include "omp_testsuite.h" |
| 4 | |
| 5 | int test_omp_master() |
| 6 | { |
| 7 | int nthreads; |
| 8 | int executing_thread; |
| 9 | |
| 10 | nthreads = 0; |
| 11 | executing_thread = -1; |
| 12 | |
| 13 | #pragma omp parallel |
| 14 | { |
Jonathan Peyton | 3731076 | 2016-05-17 21:08:52 +0000 | [diff] [blame] | 15 | #pragma omp master |
Jonathan Peyton | 614c7ef | 2015-09-21 20:41:31 +0000 | [diff] [blame] | 16 | { |
| 17 | #pragma omp critical |
| 18 | { |
| 19 | nthreads++; |
| 20 | } |
| 21 | executing_thread = omp_get_thread_num(); |
| 22 | } /* end of master*/ |
| 23 | } /* end of parallel*/ |
| 24 | return ((nthreads == 1) && (executing_thread == 0)); |
| 25 | } |
| 26 | |
| 27 | int main() |
| 28 | { |
| 29 | int i; |
| 30 | int num_failed=0; |
| 31 | |
| 32 | for(i = 0; i < REPETITIONS; i++) { |
| 33 | if(!test_omp_master()) { |
| 34 | num_failed++; |
| 35 | } |
| 36 | } |
| 37 | return num_failed; |
| 38 | } |