target-41.c 639 B

123456789101112131415161718192021222324252627282930313233
  1. /* { dg-set-target-env-var OMP_TARGET_OFFLOAD "mandatory" } */
  2. #include <omp.h>
  3. #include <stdlib.h>
  4. int v;
  5. void
  6. foo (void)
  7. {
  8. v++;
  9. }
  10. #pragma omp declare target to (v, foo)
  11. int
  12. main ()
  13. {
  14. /* OMP_TARGET_OFFLOAD=mandatory shouldn't fail for host fallback
  15. if it is because the program explicitly asked for the host
  16. fallback through if(false) or omp_get_initial_device () as
  17. the device. */
  18. #pragma omp target if (v)
  19. foo ();
  20. #pragma omp target device (omp_get_initial_device ())
  21. foo ();
  22. omp_set_default_device (omp_get_initial_device ());
  23. #pragma omp target
  24. foo ();
  25. if (v != 3)
  26. abort ();
  27. return 0;
  28. }