target-has-device-addr-4.C 712 B

123456789101112131415161718192021222324252627282930313233
  1. #include <omp.h>
  2. int
  3. main ()
  4. {
  5. int *dp = (int*)omp_target_alloc (30*sizeof(int), 0);
  6. #pragma omp target is_device_ptr(dp)
  7. for (int i = 0; i < 30; i++)
  8. dp[i] = i;
  9. int (&x)[30] = *static_cast<int(*)[30]>(static_cast<void*>(dp));
  10. #pragma omp target has_device_addr(x)
  11. for (int i = 0; i < 30; i++)
  12. x[i] = 2 * i;
  13. #pragma omp target has_device_addr(x)
  14. for (int i = 0; i < 30; i++)
  15. if (x[i] != 2 * i)
  16. __builtin_abort ();
  17. #pragma omp target has_device_addr(x[1:5])
  18. for (int i = 1; i < 6; i++)
  19. x[i] = 3 * i;
  20. #pragma omp target has_device_addr(x[1:5])
  21. for (int i = 1; i < 6; i++)
  22. if (x[i] != 3 * i)
  23. __builtin_abort ();
  24. omp_target_free (dp, 0);
  25. }