brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 92418ce Raw
85 lines · c
1// clang-format off2// RUN: %libomptarget-compile-generic && %libomptarget-run-generic 2>&1 | %fcheck-generic3// clang-format on4 5// UNSUPPORTED: aarch64-unknown-linux-gnu6// UNSUPPORTED: aarch64-unknown-linux-gnu-LTO7// UNSUPPORTED: x86_64-unknown-linux-gnu8// UNSUPPORTED: x86_64-unknown-linux-gnu-LTO9// UNSUPPORTED: s390x-ibm-linux-gnu10// UNSUPPORTED: s390x-ibm-linux-gnu-LTO11 12// REQUIRES: amdgcn-amd-amdhsa13 14#include <omp.h>15#include <stdio.h>16#include <stdlib.h>17 18int 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));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 ordered28    { output[(i - lb) / stride] = omp_get_wtime(); }29  }30 31  // verification32  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;38      }39    }40  }41 42  free(output);43 44  printf("test ordered OK\n");45 46  return 0;47}48 49int 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));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  // verification62  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;68      }69    }70  }71 72  free(output);73 74  printf("test no order OK\n");75 76  return 0;77}78 79int main() {80  // CHECK: test no order OK81  NO_order_example(0, 10, 1, 8);82  // CHECK: test ordered OK83  return ordered_example(0, 10, 1, 8);84}85