| 1 | // RUN: %libomp-compile |
| 2 | // RUN: env OMP_WAIT_POLICY=passive OMP_NUM_THREADS=32 %libomp-run 0 134217728 1 134217728 |
| 3 | // |
| 4 | // This test makes sure that large chunks sizes are handled correctly |
| 5 | // including internal runtime calculations which incorporate the chunk size |
| 6 | // Only one thread should execute all iterations. |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | #include "omp_testsuite.h" |
| 10 | |
| 11 | typedef unsigned long long ull_t; |
| 12 | |
| 13 | int main(int argc, char **argv) { |
| 14 | int i, j, lb, ub, stride, nthreads, actual_nthreads, chunk; |
| 15 | ull_t num_iters = 0; |
| 16 | ull_t counted_iters = 0; |
| 17 | int errs = 0; |
| 18 | if (argc != 5) { |
| 19 | fprintf(stderr, format: "error: incorrect number of arguments\n" ); |
| 20 | fprintf(stderr, format: "usage: %s <lb> <ub> <stride> <chunk>\n" , argv[0]); |
| 21 | exit(EXIT_FAILURE); |
| 22 | } |
| 23 | lb = atoi(nptr: argv[1]); |
| 24 | ub = atoi(nptr: argv[2]); |
| 25 | stride = atoi(nptr: argv[3]); |
| 26 | chunk = atoi(nptr: argv[4]); |
| 27 | nthreads = omp_get_max_threads(); |
| 28 | if (lb >= ub) { |
| 29 | fprintf(stderr, format: "error: lb must be less than ub\n" ); |
| 30 | exit(EXIT_FAILURE); |
| 31 | } |
| 32 | if (stride <= 0) { |
| 33 | fprintf(stderr, format: "error: stride must be positive integer\n" ); |
| 34 | exit(EXIT_FAILURE); |
| 35 | } |
| 36 | if (chunk <= 0) { |
| 37 | fprintf(stderr, format: "error: chunk must be positive integer\n" ); |
| 38 | exit(EXIT_FAILURE); |
| 39 | } |
| 40 | for (i = lb; i < ub; i += stride) |
| 41 | num_iters++; |
| 42 | |
| 43 | #pragma omp parallel num_threads(nthreads) |
| 44 | { |
| 45 | #pragma omp single |
| 46 | actual_nthreads = omp_get_num_threads(); |
| 47 | |
| 48 | if (actual_nthreads != nthreads) { |
| 49 | printf(format: "did not create enough threads, skipping test.\n" ); |
| 50 | } else { |
| 51 | #pragma omp for schedule(dynamic, chunk) |
| 52 | for (i = lb; i < ub; i += stride) { |
| 53 | counted_iters++; |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // Check that the number of iterations executed is correct |
| 59 | if (actual_nthreads == nthreads && counted_iters != num_iters) { |
| 60 | fprintf(stderr, format: "error: wrong number of final iterations counted! " |
| 61 | "num_iters=%llu, counted_iters=%llu\n" , |
| 62 | num_iters, counted_iters); |
| 63 | exit(EXIT_FAILURE); |
| 64 | } |
| 65 | |
| 66 | return EXIT_SUCCESS; |
| 67 | } |
| 68 | |