brintos

brintos / llvm-project-archived public Read only

0
0
Text · 791 B · 31ad689 Raw
30 lines · c
1// RUN: %libomp-compile-and-run2// RUN: env OMP_ALLOCATOR=omp_default_mem_space:pinned=true %libomp-run3 4#include <omp.h>5 6int main() {7  omp_alloctrait_t pinned_trait[1] = {{omp_atk_pinned, omp_atv_true}};8  omp_allocator_handle_t pinned_alloc =9      omp_init_allocator(omp_default_mem_space, 1, pinned_trait);10  omp_allocator_handle_t default_alloc = omp_get_default_allocator();11  double *a = (double *)omp_alloc(10 * sizeof(double), pinned_alloc);12  double *b = (double *)omp_alloc(10 * sizeof(double), default_alloc);13 14  if (!a || !b) return 1;15 16#pragma omp parallel for17  for (int i = 0; i < 10; i++) {18    a[i] = 0;19    b[i] = 1;20  }21 22  for (int i = 0; i < 10; i++)23    if (a[i] != 0 || b[i] != 1) return 1;24 25  omp_free(a, pinned_alloc);26  omp_free(b, default_alloc);27 28  return 0;29}30