Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / mapping / array_section_implicit_capture.c
blob1042bd23bd5efa48a14936aa7d155cde6e51e908
1 // RUN: %libomptarget-compile-generic
2 // RUN: %libomptarget-run-generic 2>&1 \
3 // RUN: | %fcheck-generic
5 #include <stdio.h>
6 #include <stdlib.h>
8 #define N 1024
9 #define FROM 64
10 #define LENGTH 128
12 int main() {
13 float *A = (float *)malloc(N * sizeof(float));
14 float *B = (float *)malloc(N * sizeof(float));
15 float *C = (float *)malloc(N * sizeof(float));
17 for (int i = 0; i < N; i++) {
18 C[i] = 0.0;
21 for (int i = 0; i < N; i++) {
22 A[i] = i;
23 B[i] = 2 * i;
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])
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 target
34 for (int i = FROM; i < FROM + LENGTH; i++) {
35 C[i] = A[i] + B[i];
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])
42 int errors = 0;
43 for (int i = FROM; i < FROM + LENGTH; i++)
44 if (C[i] != A[i] + B[i])
45 ++errors;
47 // CHECK: Success
48 if (errors)
49 fprintf(stderr, "Failure\n");
50 else
51 fprintf(stderr, "Success\n");
53 free(A);
54 free(B);
55 free(C);
57 return 0;