struct-elem-3.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <omp.h>
  2. #include <stdlib.h>
  3. struct S
  4. {
  5. int a, b, c, d;
  6. };
  7. typedef struct S S;
  8. int main (void)
  9. {
  10. int d = omp_get_default_device ();
  11. int id = omp_get_initial_device ();
  12. if (d < 0 || d >= omp_get_num_devices ())
  13. d = id;
  14. S s;
  15. #pragma omp target enter data map (alloc: s)
  16. #pragma omp target enter data map (alloc: s)
  17. #pragma omp target exit data map (release: s.a)
  18. #pragma omp target exit data map (release: s.b)
  19. /* OpenMP 5.0 structure element mapping rules describe that elements of same
  20. structure variable should allocate/deallocate in a uniform fashion, so
  21. all elements of 's' should be removed together by above 'exit data's. */
  22. if (d != id)
  23. {
  24. if (omp_target_is_present (&s, d))
  25. abort ();
  26. if (omp_target_is_present (&s.a, d))
  27. abort ();
  28. if (omp_target_is_present (&s.b, d))
  29. abort ();
  30. if (omp_target_is_present (&s.c, d))
  31. abort ();
  32. if (omp_target_is_present (&s.d, d))
  33. abort ();
  34. }
  35. #pragma omp target enter data map (alloc: s.a, s.b)
  36. #pragma omp target enter data map (alloc: s.a)
  37. #pragma omp target enter data map (alloc: s.b)
  38. #pragma omp target exit data map (release: s)
  39. #pragma omp target exit data map (release: s)
  40. #pragma omp target exit data map (release: s)
  41. /* OpenMP 5.0 structure element mapping rules describe that elements of same
  42. structure variable should allocate/deallocate in a uniform fashion, so
  43. all elements of 's' should be removed together by above 'exit data's. */
  44. if (d != id)
  45. {
  46. if (omp_target_is_present (&s, d))
  47. abort ();
  48. if (omp_target_is_present (&s.a, d))
  49. abort ();
  50. if (omp_target_is_present (&s.b, d))
  51. abort ();
  52. if (omp_target_is_present (&s.c, d))
  53. abort ();
  54. if (omp_target_is_present (&s.d, d))
  55. abort ();
  56. }
  57. return 0;
  58. }