nested-3.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <omp.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int
  5. main (void)
  6. {
  7. int e[3];
  8. memset (e, '\0', sizeof (e));
  9. omp_set_nested (1);
  10. omp_set_dynamic (0);
  11. if (omp_in_parallel ()
  12. || omp_get_level () != 0
  13. || omp_get_ancestor_thread_num (0) != 0
  14. || omp_get_ancestor_thread_num (-1) != -1
  15. || omp_get_ancestor_thread_num (1) != -1
  16. || omp_get_team_size (0) != 1
  17. || omp_get_team_size (-1) != -1
  18. || omp_get_team_size (1) != -1
  19. || omp_get_active_level () != 0)
  20. abort ();
  21. #pragma omp parallel num_threads (4)
  22. {
  23. int tn1 = omp_get_thread_num ();
  24. if (omp_in_parallel () != 1
  25. || omp_get_num_threads () != 4
  26. || tn1 >= 4 || tn1 < 0
  27. || omp_get_level () != 1
  28. || omp_get_ancestor_thread_num (0) != 0
  29. || omp_get_ancestor_thread_num (1) != tn1
  30. || omp_get_ancestor_thread_num (-1) != -1
  31. || omp_get_ancestor_thread_num (2) != -1
  32. || omp_get_team_size (0) != 1
  33. || omp_get_team_size (1) != omp_get_num_threads ()
  34. || omp_get_team_size (-1) != -1
  35. || omp_get_team_size (2) != -1
  36. || omp_get_active_level () != 1)
  37. #pragma omp atomic
  38. e[0] += 1;
  39. #pragma omp parallel if (0) num_threads(5) firstprivate(tn1)
  40. {
  41. int tn2 = omp_get_thread_num ();
  42. if (omp_in_parallel () != 1
  43. || omp_get_num_threads () != 1
  44. || tn2 != 0
  45. || omp_get_level () != 2
  46. || omp_get_ancestor_thread_num (0) != 0
  47. || omp_get_ancestor_thread_num (1) != tn1
  48. || omp_get_ancestor_thread_num (2) != tn2
  49. || omp_get_ancestor_thread_num (-1) != -1
  50. || omp_get_ancestor_thread_num (3) != -1
  51. || omp_get_team_size (0) != 1
  52. || omp_get_team_size (1) != 4
  53. || omp_get_team_size (2) != 1
  54. || omp_get_team_size (-1) != -1
  55. || omp_get_team_size (3) != -1
  56. || omp_get_active_level () != 1)
  57. #pragma omp atomic
  58. e[1] += 1;
  59. #pragma omp parallel num_threads(2) firstprivate(tn1, tn2)
  60. {
  61. int tn3 = omp_get_thread_num ();
  62. if (omp_in_parallel () != 1
  63. || omp_get_num_threads () != 2
  64. || tn3 > 1 || tn3 < 0
  65. || omp_get_level () != 3
  66. || omp_get_ancestor_thread_num (0) != 0
  67. || omp_get_ancestor_thread_num (1) != tn1
  68. || omp_get_ancestor_thread_num (2) != tn2
  69. || omp_get_ancestor_thread_num (3) != tn3
  70. || omp_get_ancestor_thread_num (-1) != -1
  71. || omp_get_ancestor_thread_num (4) != -1
  72. || omp_get_team_size (0) != 1
  73. || omp_get_team_size (1) != 4
  74. || omp_get_team_size (2) != 1
  75. || omp_get_team_size (3) != 2
  76. || omp_get_team_size (-1) != -1
  77. || omp_get_team_size (4) != -1
  78. || omp_get_active_level () != 2)
  79. #pragma omp atomic
  80. e[2] += 1;
  81. }
  82. }
  83. }
  84. if (e[0] || e[1] || e[2])
  85. abort ();
  86. return 0;
  87. }