45 lines · c
1// RUN: %libomptarget-compile-generic && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-generic 2>&1 | %fcheck-generic2// REQUIRES: libomptarget-debug3 4#include <stdio.h>5#include <stdlib.h>6 7int *allocate(size_t n) {8 int *ptr = malloc(sizeof(int) * n);9#pragma omp target enter data map(to : ptr[ : n])10 return ptr;11}12 13void deallocate(int *ptr, size_t n) {14#pragma omp target exit data map(delete : ptr[ : n])15 free(ptr);16}17 18#pragma omp declare target19int *cnt;20void foo() { ++(*cnt); }21#pragma omp end declare target22 23int main(void) {24 int *A = allocate(10);25 int *V = allocate(10);26 deallocate(A, 10);27 deallocate(V, 10);28 // CHECK-NOT: RefCount=229 cnt = malloc(sizeof(int));30 *cnt = 0;31#pragma omp target map(cnt[ : 1])32 foo();33 printf("Cnt = %d.\n", *cnt);34 // CHECK: Cnt = 1.35 *cnt = 0;36#pragma omp target data map(cnt[ : 1])37#pragma omp target38 foo();39 printf("Cnt = %d.\n", *cnt);40 // CHECK: Cnt = 1.41 free(cnt);42 43 return 0;44}45