critical-hint-1.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* { dg-do compile } */
  2. #include <omp.h>
  3. void
  4. example_criticial ()
  5. {
  6. int a, b;
  7. #pragma omp parallel for
  8. for (int i = 0; i < 10; ++i)
  9. {
  10. #pragma omp critical hint(omp_sync_hint_none) /* OK */
  11. a += i;
  12. #pragma omp critical (HASH) hint(omp_sync_hint_none) /* OK */
  13. a += i;
  14. #pragma omp critical (HASH2) hint(omp_sync_hint_uncontended) /* OK */
  15. a += i;
  16. #pragma omp critical (HASH3) hint(omp_sync_hint_contended) /* OK */
  17. a += i;
  18. #pragma omp critical (HASH4) hint(omp_sync_hint_speculative) /* OK */
  19. a += i;
  20. #pragma omp critical (HASH5) hint(omp_sync_hint_nonspeculative) /* OK */
  21. a += i;
  22. #pragma omp critical (HASH6) hint(omp_sync_hint_contended + omp_sync_hint_speculative) /* OK */
  23. a += i;
  24. #pragma omp critical (HASH6) hint(omp_sync_hint_contended | omp_sync_hint_speculative) /* OK */
  25. a += i;
  26. /* Accepted but invalid: different hint for same name. */
  27. #pragma omp critical (HASH6) hint(omp_sync_hint_uncontended + omp_sync_hint_speculative)
  28. a += i;
  29. /* Accepted but invalid: Some random integer expr. */
  30. #pragma omp critical (HASH) hint(omp_sync_hint_speculative + 1 + 2)
  31. a += i;
  32. #pragma omp critical (HASH) hint(-3) /* { dg-error "expected constant integer expression" } */
  33. a += i;
  34. #pragma omp critical (HASH2) hint(b) /* { dg-error "constant integer expression" } */
  35. a += i;
  36. /*
  37. Fails with gcc as 'expected identifier' and
  38. with g++ as "clause requires a name, except when 'omp_sync_hint_none'"
  39. #pragma omp critical () hint(omp_sync_hint_speculative)
  40. a += i;
  41. */
  42. #pragma omp critical hint(omp_sync_hint_speculative) /* { dg-error "with 'hint' clause requires a name, except when 'omp_sync_hint_none' is used" } */
  43. a += i;
  44. }
  45. }