brintos

brintos / llvm-project-archived public Read only

0
0
Text · 823 B · 8876fc9 Raw
34 lines · c
1// RUN: %libomptarget-compile-run-and-check-generic2 3#include <omp.h>4#include <stdio.h>5#include <assert.h>6 7int main() {8  const int N = 64;9 10  int *device_ptr =11      omp_alloc(N * sizeof(int), llvm_omp_target_device_mem_alloc);12 13#pragma omp target teams distribute parallel for is_device_ptr(device_ptr)14  for (int i = 0; i < N; ++i) {15    device_ptr[i] = 1;16  }17 18  int sum = 0;19#pragma omp target parallel for reduction(+ : sum) is_device_ptr(device_ptr)20  for (int i = 0; i < N; ++i)21    sum += device_ptr[i];22 23  // CHECK: PASS24  if (sum == N)25    printf("PASS\n");26 27  omp_free(device_ptr, llvm_omp_target_device_mem_alloc);28 29  // Make sure this interface works.30  void *ptr = omp_alloc(0, llvm_omp_target_device_mem_alloc);31  assert(!ptr && "Ptr not (nullptr)");32  omp_free(ptr, llvm_omp_target_device_mem_alloc);33}34