xref: /llvm-project/offload/test/offloading/dynamic-schedule.cpp (revision 1a0cf245ac86c2f35c89cab47f83e9b474032e41)
11a478a69SGheorghe-Teodor Bercea // clang-format off
21a478a69SGheorghe-Teodor Bercea // RUN: %libomptarget-compilexx-generic && %libomptarget-run-generic 2>&1 | %fcheck-generic
31a478a69SGheorghe-Teodor Bercea // clang-format on
41a478a69SGheorghe-Teodor Bercea 
51a478a69SGheorghe-Teodor Bercea // UNSUPPORTED: aarch64-unknown-linux-gnu
61a478a69SGheorghe-Teodor Bercea // UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
7*1a0cf245SJan Patrick Lehr // UNSUPPORTED: x86_64-unknown-linux-gnu
8*1a0cf245SJan Patrick Lehr // UNSUPPORTED: x86_64-unknown-linux-gnu-LTO
91a478a69SGheorghe-Teodor Bercea // UNSUPPORTED: s390x-ibm-linux-gnu
101a478a69SGheorghe-Teodor Bercea // UNSUPPORTED: s390x-ibm-linux-gnu-LTO
111a478a69SGheorghe-Teodor Bercea 
121a478a69SGheorghe-Teodor Bercea // REQUIRES: amdgcn-amd-amdhsa
131a478a69SGheorghe-Teodor Bercea 
141a478a69SGheorghe-Teodor Bercea #include <omp.h>
151a478a69SGheorghe-Teodor Bercea #include <stdio.h>
161a478a69SGheorghe-Teodor Bercea 
171a478a69SGheorghe-Teodor Bercea #define N 100
181a478a69SGheorghe-Teodor Bercea 
191a478a69SGheorghe-Teodor Bercea bool schedule(int lb, int ub, int stride, int chunk) {
201a478a69SGheorghe-Teodor Bercea   int i;
211a478a69SGheorghe-Teodor Bercea 
221a478a69SGheorghe-Teodor Bercea   int result[N];
231a478a69SGheorghe-Teodor Bercea   for (i = 0; i < N; i++) {
241a478a69SGheorghe-Teodor Bercea     result[i] = 0;
251a478a69SGheorghe-Teodor Bercea   }
261a478a69SGheorghe-Teodor Bercea 
271a478a69SGheorghe-Teodor Bercea #pragma omp target parallel for schedule(dynamic, chunk)                       \
281a478a69SGheorghe-Teodor Bercea     map(tofrom : result[ : N])
291a478a69SGheorghe-Teodor Bercea   for (i = lb; i < ub; i += stride) {
301a478a69SGheorghe-Teodor Bercea     result[i] += i;
311a478a69SGheorghe-Teodor Bercea   }
321a478a69SGheorghe-Teodor Bercea 
331a478a69SGheorghe-Teodor Bercea   int value = 0;
341a478a69SGheorghe-Teodor Bercea   bool success = true;
351a478a69SGheorghe-Teodor Bercea   for (i = 0; i < N; i += stride) {
361a478a69SGheorghe-Teodor Bercea     if (value != result[i]) {
371a478a69SGheorghe-Teodor Bercea       printf("ERROR: result[%d] = %d instead of %d\n", i, result[i], value);
381a478a69SGheorghe-Teodor Bercea       success = false;
391a478a69SGheorghe-Teodor Bercea       break;
401a478a69SGheorghe-Teodor Bercea     }
411a478a69SGheorghe-Teodor Bercea     value += stride;
421a478a69SGheorghe-Teodor Bercea   }
431a478a69SGheorghe-Teodor Bercea 
441a478a69SGheorghe-Teodor Bercea   return success;
451a478a69SGheorghe-Teodor Bercea }
461a478a69SGheorghe-Teodor Bercea 
471a478a69SGheorghe-Teodor Bercea int main() {
481a478a69SGheorghe-Teodor Bercea   // CHECK: SUCCESS CHUNK SIZE 1
491a478a69SGheorghe-Teodor Bercea   if (schedule(0, N, 5, 1))
501a478a69SGheorghe-Teodor Bercea     printf("SUCCESS CHUNK SIZE 1\n");
511a478a69SGheorghe-Teodor Bercea 
521a478a69SGheorghe-Teodor Bercea   // CHECK: SUCCESS CHUNK SIZE 3
531a478a69SGheorghe-Teodor Bercea   if (schedule(0, N, 5, 3))
541a478a69SGheorghe-Teodor Bercea     printf("SUCCESS CHUNK SIZE 3\n");
551a478a69SGheorghe-Teodor Bercea 
561a478a69SGheorghe-Teodor Bercea   return 0;
571a478a69SGheorghe-Teodor Bercea }
58