[Instrumentation] Fix a warning
[llvm-project.git] / offload / test / offloading / schedule.c
blob92418cea8bd3320211cd94576f9b8d9e4630ae41
1 // clang-format off
2 // RUN: %libomptarget-compile-generic && %libomptarget-run-generic 2>&1 | %fcheck-generic
3 // clang-format on
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
12 // REQUIRES: amdgcn-amd-amdhsa
14 #include <omp.h>
15 #include <stdio.h>
16 #include <stdlib.h>
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 * sizeof(double));
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(); }
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("Fail to schedule in order.\n");
36 free(output);
37 return 1;
42 free(output);
44 printf("test ordered OK\n");
46 return 0;
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 * sizeof(double));
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();
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("Fail to schedule in order.\n");
66 free(output);
67 return 1;
72 free(output);
74 printf("test no order OK\n");
76 return 0;
79 int main() {
80 // CHECK: test no order OK
81 NO_order_example(0, 10, 1, 8);
82 // CHECK: test ordered OK
83 return ordered_example(0, 10, 1, 8);