| 1 | // RUN: %libomp-compile |
| 2 | // RUN: env OMP_SCHEDULE=monotonic:dynamic,50 %libomp-run monotonic dynamic 50 |
| 3 | // RUN: env OMP_SCHEDULE=monotonic:guided,51 %libomp-run monotonic guided 51 |
| 4 | // RUN: env OMP_SCHEDULE=monotonic:static,52 %libomp-run monotonic static 52 |
| 5 | // RUN: env OMP_SCHEDULE=nonmonotonic:dynamic,53 %libomp-run nonmonotonic dynamic 53 |
| 6 | // RUN: env OMP_SCHEDULE=nonmonotonic:guided,54 %libomp-run nonmonotonic guided 54 |
| 7 | |
| 8 | // The test checks OMP 5.0 monotonic/nonmonotonic OMP_SCHEDULE parsing |
| 9 | // The nonmonotonic tests see if the parser accepts nonmonotonic, if the |
| 10 | // parser doesn't then a static schedule is assumed |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <string.h> |
| 14 | #include <omp.h> |
| 15 | |
| 16 | int err = 0; |
| 17 | |
| 18 | omp_sched_t sched_without_modifiers(omp_sched_t sched) { |
| 19 | return (omp_sched_t)((int)sched & ~((int)omp_sched_monotonic)); |
| 20 | } |
| 21 | |
| 22 | int sched_has_modifiers(omp_sched_t sched, omp_sched_t modifiers) { |
| 23 | return (int)sched & (int)modifiers; |
| 24 | } |
| 25 | |
| 26 | // check that sched = hope | modifiers |
| 27 | void check_schedule(const char *, const omp_sched_t sched, int chunk, |
| 28 | omp_sched_t hope_sched, int hope_chunk) { |
| 29 | |
| 30 | if (sched != hope_sched || chunk != hope_chunk) { |
| 31 | ++err; |
| 32 | printf(format: "Error: %s: schedule: (%d, %d) is not equal to (%d, %d)\n" , extra, |
| 33 | (int)hope_sched, hope_chunk, (int)sched, chunk); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | omp_sched_t str2omp_sched(const char *str) { |
| 38 | if (!strcmp(s1: str, s2: "dynamic" )) |
| 39 | return omp_sched_dynamic; |
| 40 | if (!strcmp(s1: str, s2: "static" )) |
| 41 | return omp_sched_static; |
| 42 | if (!strcmp(s1: str, s2: "guided" )) |
| 43 | return omp_sched_guided; |
| 44 | printf(format: "Error: Unknown schedule type: %s\n" , str); |
| 45 | exit(status: 1); |
| 46 | } |
| 47 | |
| 48 | int is_monotonic(const char *str) { return !strcmp(s1: str, s2: "monotonic" ); } |
| 49 | |
| 50 | int main(int argc, char **argv) { |
| 51 | int i, monotonic, chunk, ref_chunk; |
| 52 | omp_sched_t sched, ref_sched; |
| 53 | |
| 54 | if (argc != 4) { |
| 55 | printf(format: "Error: usage: <executable> monotonic|nonmonotonic <schedule> " |
| 56 | "<chunk-size>\n" ); |
| 57 | exit(status: 1); |
| 58 | } |
| 59 | |
| 60 | monotonic = is_monotonic(str: argv[1]); |
| 61 | ref_sched = str2omp_sched(str: argv[2]); |
| 62 | ref_chunk = atoi(nptr: argv[3]); |
| 63 | |
| 64 | omp_get_schedule(&sched, &chunk); |
| 65 | |
| 66 | if (monotonic && !sched_has_modifiers(sched, modifiers: omp_sched_monotonic)) { |
| 67 | printf(format: "Error: sched (0x%x) does not have monotonic modifier\n" , |
| 68 | (int)sched); |
| 69 | ++err; |
| 70 | } |
| 71 | sched = sched_without_modifiers(sched); |
| 72 | if (sched != ref_sched) { |
| 73 | printf(format: "Error: sched (0x%x) is not 0x%x\n" , (int)sched, (int)ref_sched); |
| 74 | ++err; |
| 75 | } |
| 76 | if (chunk != ref_chunk) { |
| 77 | printf(format: "Error: chunk is not %d\n" , ref_chunk); |
| 78 | ++err; |
| 79 | } |
| 80 | if (err > 0) { |
| 81 | printf(format: "Failed\n" ); |
| 82 | return 1; |
| 83 | } |
| 84 | printf(format: "Passed\n" ); |
| 85 | return 0; |
| 86 | } |
| 87 | |