threadprivate3.f90 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ! { dg-do run }
  2. ! { dg-require-effective-target tls_runtime }
  3. module threadprivate3
  4. integer, dimension(:,:), pointer :: foo => NULL()
  5. !$omp threadprivate (foo)
  6. end module threadprivate3
  7. use omp_lib
  8. use threadprivate3
  9. integer, dimension(:), pointer :: bar1
  10. integer, dimension(2), target :: bar2, var
  11. common /thrc/ bar1, bar2
  12. !$omp threadprivate (/thrc/)
  13. integer, dimension(:), pointer, save :: bar3 => NULL()
  14. !$omp threadprivate (bar3)
  15. logical :: l
  16. type tt
  17. integer :: a
  18. integer :: b = 32
  19. end type tt
  20. type (tt), save :: baz
  21. !$omp threadprivate (baz)
  22. l = .false.
  23. call omp_set_dynamic (.false.)
  24. call omp_set_num_threads (4)
  25. var = 6
  26. !$omp parallel num_threads (4) reduction (.or.:l)
  27. bar2 = omp_get_thread_num ()
  28. l = associated (bar3)
  29. bar1 => bar2
  30. l = l.or..not.associated (bar1)
  31. l = l.or..not.associated (bar1, bar2)
  32. l = l.or.any (bar1.ne.omp_get_thread_num ())
  33. nullify (bar1)
  34. l = l.or.associated (bar1)
  35. allocate (bar3 (4))
  36. l = l.or..not.associated (bar3)
  37. bar3 = omp_get_thread_num () - 2
  38. if (omp_get_thread_num () .ne. 0) then
  39. deallocate (bar3)
  40. if (associated (bar3)) call abort
  41. else
  42. bar1 => var
  43. end if
  44. bar2 = omp_get_thread_num () * 6 + 130
  45. l = l.or.(baz%b.ne.32)
  46. baz%a = omp_get_thread_num () * 2
  47. baz%b = omp_get_thread_num () * 2 + 1
  48. !$omp end parallel
  49. if (l) call abort
  50. if (.not.associated (bar1)) call abort
  51. if (any (bar1.ne.6)) call abort
  52. if (.not.associated (bar3)) call abort
  53. if (any (bar3 .ne. -2)) call abort
  54. deallocate (bar3)
  55. if (associated (bar3)) call abort
  56. allocate (bar3 (10))
  57. bar3 = 17
  58. !$omp parallel copyin (bar1, bar2, bar3, baz) num_threads (4) &
  59. !$omp& reduction (.or.:l)
  60. l = l.or..not.associated (bar1)
  61. l = l.or.any (bar1.ne.6)
  62. l = l.or.any (bar2.ne.130)
  63. l = l.or..not.associated (bar3)
  64. l = l.or.size (bar3).ne.10
  65. l = l.or.any (bar3.ne.17)
  66. allocate (bar1 (4))
  67. bar1 = omp_get_thread_num ()
  68. bar2 = omp_get_thread_num () + 8
  69. l = l.or.(baz%a.ne.0)
  70. l = l.or.(baz%b.ne.1)
  71. baz%a = omp_get_thread_num () * 3 + 4
  72. baz%b = omp_get_thread_num () * 3 + 5
  73. !$omp barrier
  74. if (omp_get_thread_num () .eq. 0) then
  75. deallocate (bar3)
  76. end if
  77. bar3 => bar2
  78. !$omp barrier
  79. l = l.or..not.associated (bar1)
  80. l = l.or..not.associated (bar3)
  81. l = l.or.any (bar1.ne.omp_get_thread_num ())
  82. l = l.or.size (bar1).ne.4
  83. l = l.or.any (bar2.ne.omp_get_thread_num () + 8)
  84. l = l.or.any (bar3.ne.omp_get_thread_num () + 8)
  85. l = l.or.size (bar3).ne.2
  86. l = l.or.(baz%a .ne. omp_get_thread_num () * 3 + 4)
  87. l = l.or.(baz%b .ne. omp_get_thread_num () * 3 + 5)
  88. !$omp end parallel
  89. if (l) call abort
  90. end
  91. ! { dg-final { cleanup-modules "threadprivate3" } }