| 1 |
// RUN: %libomp-compile |
| 2 |
// RUN: env OMP_SCHEDULE=nonmonotonic:dynamic,10 %libomp-run |
| 3 |
|
| 4 |
// The test checks iterations distribution for OMP 5.0 nonmonotonic OMP_SCHEDULE |
| 5 |
// case #threads > #chunks (fallback to monotonic dynamic) |
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
#include <omp.h> |
| 9 |
|
| 10 |
#define ITERS 100 |
| 11 |
#define CHUNK 10 |
| 12 |
int err = 0; |
| 13 |
|
| 14 |
int main(int argc, char **argv) { |
| 15 |
int i, ch, it[ITERS]; |
| 16 |
omp_set_num_threads(16); // #threads is bigger than #chunks |
| 17 |
#pragma omp parallel for schedule(runtime) |
| 18 |
for (i = 0; i < ITERS; ++i) { |
| 19 |
it[i] = omp_get_thread_num(); |
| 20 |
} |
| 21 |
// check that each chunk executed by single thread |
| 22 |
for (ch = 0; ch < ITERS/CHUNK; ++ch) { |
| 23 |
int iter = ch * CHUNK; |
| 24 |
int nt = it[iter]; // thread number |
| 25 |
for (i = 1; i < CHUNK; ++i) { |
| 26 |
#if _DEBUG |
| 27 |
printf("iter %d: (%d %d)\n", iter + i, nt, it[iter + i]); |
| 28 |
#endif |
| 29 |
if (nt != it[iter + i]) { |
| 30 |
err++; |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
if (err > 0) { |
| 35 |
printf("Failed, err = %d\n", err); |
| 36 |
return 1; |
| 37 |
} |
| 38 |
printf("Passed\n"); |
| 39 |
return 0; |
| 40 |
} |