ordered-3.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <stdlib.h>
  2. int cnt;
  3. void
  4. check (int x)
  5. {
  6. if (cnt++ != x)
  7. abort ();
  8. }
  9. int
  10. main (void)
  11. {
  12. int j;
  13. cnt = 0;
  14. #pragma omp parallel for ordered schedule (static, 1) num_threads (4) if (0)
  15. for (j = 0; j < 1000; j++)
  16. {
  17. #pragma omp ordered
  18. check (j);
  19. }
  20. cnt = 0;
  21. #pragma omp parallel for ordered schedule (static, 1) num_threads (4) if (1)
  22. for (j = 0; j < 1000; j++)
  23. {
  24. #pragma omp ordered
  25. check (j);
  26. }
  27. cnt = 0;
  28. #pragma omp parallel for ordered schedule (runtime) num_threads (4) if (0)
  29. for (j = 0; j < 1000; j++)
  30. {
  31. #pragma omp ordered
  32. check (j);
  33. }
  34. cnt = 0;
  35. #pragma omp parallel for ordered schedule (runtime) num_threads (4) if (1)
  36. for (j = 0; j < 1000; j++)
  37. {
  38. #pragma omp ordered
  39. check (j);
  40. }
  41. cnt = 0;
  42. #pragma omp parallel for ordered schedule (dynamic) num_threads (4) if (0)
  43. for (j = 0; j < 1000; j++)
  44. {
  45. #pragma omp ordered
  46. check (j);
  47. }
  48. cnt = 0;
  49. #pragma omp parallel for ordered schedule (dynamic) num_threads (4) if (1)
  50. for (j = 0; j < 1000; j++)
  51. {
  52. #pragma omp ordered
  53. check (j);
  54. }
  55. cnt = 0;
  56. #pragma omp parallel for ordered schedule (guided) num_threads (4) if (0)
  57. for (j = 0; j < 1000; j++)
  58. {
  59. #pragma omp ordered
  60. check (j);
  61. }
  62. cnt = 0;
  63. #pragma omp parallel for ordered schedule (guided) num_threads (4) if (1)
  64. for (j = 0; j < 1000; j++)
  65. {
  66. #pragma omp ordered
  67. check (j);
  68. }
  69. return 0;
  70. }