brintos

brintos / llvm-project-archived public Read only

0
0
Text · 661 B · f5fad8b Raw
35 lines · cpp
1// RUN: %libomptarget-compile-run-and-check-generic2 3#include <cstdio>4#include <cstdlib>5 6#define NUM 10247 8class C {9public:10  int *a;11};12 13#pragma omp declare mapper(id : C s) map(s.a[0 : NUM])14 15int main() {16  C c;17  c.a = (int *)malloc(sizeof(int) * NUM);18  for (int i = 0; i < NUM; i++) {19    c.a[i] = 1;20  }21#pragma omp target enter data map(mapper(id), to : c)22#pragma omp target teams distribute parallel for23  for (int i = 0; i < NUM; i++) {24    ++c.a[i];25  }26#pragma omp target exit data map(mapper(id), from : c)27  int sum = 0;28  for (int i = 0; i < NUM; i++) {29    sum += c.a[i];30  }31  // CHECK: Sum = 204832  printf("Sum = %d\n", sum);33  return 0;34}35