thread-limit-2.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* { dg-do run } */
  2. /* { dg-set-target-env-var OMP_THREAD_LIMIT "9" } */
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <omp.h>
  6. int
  7. main ()
  8. {
  9. if (omp_get_thread_limit () != 9)
  10. return 0;
  11. omp_set_dynamic (0);
  12. #pragma omp parallel num_threads (8)
  13. if (omp_get_num_threads () != 8)
  14. abort ();
  15. #pragma omp parallel num_threads (16)
  16. if (omp_get_num_threads () > 9)
  17. abort ();
  18. #pragma omp target if (0)
  19. #pragma omp teams thread_limit (6)
  20. {
  21. if (omp_get_thread_limit () > 6)
  22. abort ();
  23. if (omp_get_thread_limit () == 6)
  24. {
  25. omp_set_dynamic (0);
  26. omp_set_nested (1);
  27. #pragma omp parallel num_threads (3)
  28. if (omp_get_num_threads () != 3)
  29. abort ();
  30. #pragma omp parallel num_threads (3)
  31. if (omp_get_num_threads () != 3)
  32. abort ();
  33. #pragma omp parallel num_threads (8)
  34. if (omp_get_num_threads () > 6)
  35. abort ();
  36. #pragma omp parallel num_threads (6)
  37. if (omp_get_num_threads () != 6)
  38. abort ();
  39. int cnt = 0;
  40. #pragma omp parallel num_threads (5)
  41. #pragma omp parallel num_threads (5)
  42. #pragma omp parallel num_threads (2)
  43. {
  44. int v;
  45. #pragma omp atomic capture
  46. v = ++cnt;
  47. if (v > 6)
  48. abort ();
  49. usleep (10000);
  50. #pragma omp atomic
  51. --cnt;
  52. }
  53. }
  54. }
  55. return 0;
  56. }