llvm-project
58 строк · 1.3 Кб
1// RUN: %libomptarget-compile-generic
2// RUN: %libomptarget-run-generic 2>&1 \
3// RUN: | %fcheck-generic
4
5#include <stdio.h>6#include <stdlib.h>7
8#define N 10249#define FROM 6410#define LENGTH 12811
12int main() {13float *A = (float *)malloc(N * sizeof(float));14float *B = (float *)malloc(N * sizeof(float));15float *C = (float *)malloc(N * sizeof(float));16
17for (int i = 0; i < N; i++) {18C[i] = 0.0;19}20
21for (int i = 0; i < N; i++) {22A[i] = i;23B[i] = 2 * i;24}25
26#pragma omp target enter data map(to : A[FROM : LENGTH], B[FROM : LENGTH])27#pragma omp target enter data map(alloc : C[FROM : LENGTH])28
29// A, B and C have been mapped starting at index FROM, but inside the kernel
30// they are captured implicitly so the library must look them up using their
31// base address.
32#pragma omp target33{34for (int i = FROM; i < FROM + LENGTH; i++) {35C[i] = A[i] + B[i];36}37}38
39#pragma omp target exit data map(from : C[FROM : LENGTH])40#pragma omp target exit data map(delete : A[FROM : LENGTH], B[FROM : LENGTH])41
42int errors = 0;43for (int i = FROM; i < FROM + LENGTH; i++)44if (C[i] != A[i] + B[i])45++errors;46
47// CHECK: Success48if (errors)49fprintf(stderr, "Failure\n");50else51fprintf(stderr, "Success\n");52
53free(A);54free(B);55free(C);56
57return 0;58}
59