| 1 | // clang-format off |
| 2 | // RUN: %libomptarget-compile-generic && %libomptarget-run-generic 2>&1 | %fcheck-generic |
| 3 | // clang-format on |
| 4 | |
| 5 | // UNSUPPORTED: aarch64-unknown-linux-gnu |
| 6 | // UNSUPPORTED: aarch64-unknown-linux-gnu-LTO |
| 7 | // UNSUPPORTED: x86_64-unknown-linux-gnu |
| 8 | // UNSUPPORTED: x86_64-unknown-linux-gnu-LTO |
| 9 | // UNSUPPORTED: s390x-ibm-linux-gnu |
| 10 | // UNSUPPORTED: s390x-ibm-linux-gnu-LTO |
| 11 | |
| 12 | // REQUIRES: amdgcn-amd-amdhsa |
| 13 | |
| 14 | #include <omp.h> |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | |
| 18 | int ordered_example(int lb, int ub, int stride, int nteams) { |
| 19 | int i; |
| 20 | int size = (ub - lb) / stride; |
| 21 | double *output = (double *)malloc(size: size * sizeof(double)); |
| 22 | |
| 23 | #pragma omp target teams map(from : output[0 : size]) num_teams(nteams) \ |
| 24 | thread_limit(128) |
| 25 | #pragma omp parallel for ordered schedule(dynamic) |
| 26 | for (i = lb; i < ub; i += stride) { |
| 27 | #pragma omp ordered |
| 28 | { output[(i - lb) / stride] = omp_get_wtime(); } |
| 29 | } |
| 30 | |
| 31 | // verification |
| 32 | for (int j = 0; j < size; j++) { |
| 33 | for (int jj = j + 1; jj < size; jj++) { |
| 34 | if (output[j] > output[jj]) { |
| 35 | printf(format: "Fail to schedule in order.\n" ); |
| 36 | free(ptr: output); |
| 37 | return 1; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | free(ptr: output); |
| 43 | |
| 44 | printf(format: "test ordered OK\n" ); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | int NO_order_example(int lb, int ub, int stride, int nteams) { |
| 50 | int i; |
| 51 | int size = (ub - lb) / stride; |
| 52 | double *output = (double *)malloc(size: size * sizeof(double)); |
| 53 | |
| 54 | #pragma omp target teams map(from : output[0 : size]) num_teams(nteams) \ |
| 55 | thread_limit(128) |
| 56 | #pragma omp parallel for schedule(dynamic) |
| 57 | for (i = lb; i < ub; i += stride) { |
| 58 | output[(i - lb) / stride] = omp_get_wtime(); |
| 59 | } |
| 60 | |
| 61 | // verification |
| 62 | for (int j = 0; j < size; j++) { |
| 63 | for (int jj = j + 1; jj < size; jj++) { |
| 64 | if (output[j] > output[jj]) { |
| 65 | printf(format: "Fail to schedule in order.\n" ); |
| 66 | free(ptr: output); |
| 67 | return 1; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | free(ptr: output); |
| 73 | |
| 74 | printf(format: "test no order OK\n" ); |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | int main() { |
| 80 | // CHECK: test no order OK |
| 81 | NO_order_example(lb: 0, ub: 10, stride: 1, nteams: 8); |
| 82 | // CHECK: test ordered OK |
| 83 | return ordered_example(lb: 0, ub: 10, stride: 1, nteams: 8); |
| 84 | } |
| 85 | |