| 1 | // RUN: %libomp-compile |
| 2 | // RUN: env KMP_DISP_NUM_BUFFERS=0 %libomp-run |
| 3 | // RUN: env KMP_DISP_NUM_BUFFERS=1 %libomp-run |
| 4 | // RUN: env KMP_DISP_NUM_BUFFERS=3 %libomp-run |
| 5 | // RUN: env KMP_DISP_NUM_BUFFERS=4 %libomp-run |
| 6 | // RUN: env KMP_DISP_NUM_BUFFERS=7 %libomp-run |
| 7 | // RUN: %libomp-compile -DMY_SCHEDULE=guided |
| 8 | // RUN: env KMP_DISP_NUM_BUFFERS=1 %libomp-run |
| 9 | // RUN: env KMP_DISP_NUM_BUFFERS=3 %libomp-run |
| 10 | // RUN: env KMP_DISP_NUM_BUFFERS=4 %libomp-run |
| 11 | // RUN: env KMP_DISP_NUM_BUFFERS=7 %libomp-run |
| 12 | // UNSUPPORTED: clang-11, clang-12 |
| 13 | #include <stdio.h> |
| 14 | #include <omp.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <limits.h> |
| 17 | #include "omp_testsuite.h" |
| 18 | |
| 19 | #define INCR 7 |
| 20 | #define MY_MAX 200 |
| 21 | #define MY_MIN -200 |
| 22 | #define NUM_LOOPS 100 |
| 23 | #ifndef MY_SCHEDULE |
| 24 | # define MY_SCHEDULE dynamic |
| 25 | #endif |
| 26 | |
| 27 | int a, b, a_known_value, b_known_value; |
| 28 | |
| 29 | int test_kmp_set_disp_num_buffers() |
| 30 | { |
| 31 | int success = 1; |
| 32 | a = 0; |
| 33 | b = 0; |
| 34 | // run many small dynamic loops to stress the dispatch buffer system |
| 35 | #pragma omp parallel |
| 36 | { |
| 37 | int i,j; |
| 38 | for (j = 0; j < NUM_LOOPS; j++) { |
| 39 | #pragma omp for schedule(MY_SCHEDULE) nowait |
| 40 | for (i = MY_MIN; i < MY_MAX; i+=INCR) { |
| 41 | #pragma omp atomic |
| 42 | a++; |
| 43 | } |
| 44 | #pragma omp for schedule(MY_SCHEDULE) nowait |
| 45 | for (i = MY_MAX; i >= MY_MIN; i-=INCR) { |
| 46 | #pragma omp atomic |
| 47 | b++; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | // detect failure |
| 52 | if (a != a_known_value || b != b_known_value) { |
| 53 | success = 0; |
| 54 | printf(format: "a = %d (should be %d), b = %d (should be %d)\n" , a, a_known_value, |
| 55 | b, b_known_value); |
| 56 | } |
| 57 | return success; |
| 58 | } |
| 59 | |
| 60 | int main(int argc, char** argv) |
| 61 | { |
| 62 | int i,j; |
| 63 | int num_failed=0; |
| 64 | |
| 65 | // figure out the known values to compare with calculated result |
| 66 | a_known_value = 0; |
| 67 | b_known_value = 0; |
| 68 | |
| 69 | for (j = 0; j < NUM_LOOPS; j++) { |
| 70 | for (i = MY_MIN; i < MY_MAX; i+=INCR) |
| 71 | a_known_value++; |
| 72 | for (i = MY_MAX; i >= MY_MIN; i-=INCR) |
| 73 | b_known_value++; |
| 74 | } |
| 75 | |
| 76 | for(i = 0; i < REPETITIONS; i++) { |
| 77 | if(!test_kmp_set_disp_num_buffers()) { |
| 78 | num_failed++; |
| 79 | } |
| 80 | } |
| 81 | if (num_failed == 0) |
| 82 | printf(format: "passed\n" ); |
| 83 | else |
| 84 | printf(format: "failed %d\n" , num_failed); |
| 85 | return num_failed; |
| 86 | } |
| 87 | |