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