threadprivate2.f90 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ! { dg-do run }
  2. ! { dg-require-effective-target tls_runtime }
  3. module threadprivate2
  4. integer, dimension(:,:), allocatable :: foo
  5. !$omp threadprivate (foo)
  6. end module threadprivate2
  7. use omp_lib
  8. use threadprivate2
  9. integer, dimension(:), pointer :: bar1
  10. integer, dimension(2), target :: bar2
  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. !$omp parallel num_threads (4) reduction (.or.:l)
  26. l = allocated (foo)
  27. allocate (foo (6 + omp_get_thread_num (), 3))
  28. l = l.or..not.allocated (foo)
  29. l = l.or.size (foo).ne.(18 + 3 * omp_get_thread_num ())
  30. foo = omp_get_thread_num () + 1
  31. bar2 = omp_get_thread_num ()
  32. l = l.or.associated (bar3)
  33. bar1 => bar2
  34. l = l.or..not.associated (bar1)
  35. l = l.or..not.associated (bar1, bar2)
  36. l = l.or.any (bar1.ne.omp_get_thread_num ())
  37. nullify (bar1)
  38. l = l.or.associated (bar1)
  39. allocate (bar3 (4))
  40. l = l.or..not.associated (bar3)
  41. bar3 = omp_get_thread_num () - 2
  42. l = l.or.(baz%b.ne.32)
  43. baz%a = omp_get_thread_num () * 2
  44. baz%b = omp_get_thread_num () * 2 + 1
  45. !$omp end parallel
  46. if (l) call abort
  47. if (.not.allocated (foo)) call abort
  48. if (size (foo).ne.18) call abort
  49. if (any (foo.ne.1)) call abort
  50. if (associated (bar1)) call abort
  51. if (.not.associated (bar3)) call abort
  52. if (any (bar3 .ne. -2)) call abort
  53. deallocate (bar3)
  54. if (associated (bar3)) call abort
  55. !$omp parallel num_threads (4) reduction (.or.:l)
  56. l = l.or..not.allocated (foo)
  57. l = l.or.size (foo).ne.(18 + 3 * omp_get_thread_num ())
  58. l = l.or.any (foo.ne.(omp_get_thread_num () + 1))
  59. if (omp_get_thread_num () .ne. 0) then
  60. deallocate (foo)
  61. l = l.or.allocated (foo)
  62. end if
  63. l = l.or.associated (bar1)
  64. if (omp_get_thread_num () .ne. 0) then
  65. l = l.or..not.associated (bar3)
  66. l = l.or.any (bar3 .ne. omp_get_thread_num () - 2)
  67. deallocate (bar3)
  68. end if
  69. l = l.or.associated (bar3)
  70. l = l.or.(baz%a.ne.(omp_get_thread_num () * 2))
  71. l = l.or.(baz%b.ne.(omp_get_thread_num () * 2 + 1))
  72. !$omp end parallel
  73. if (l) call abort
  74. if (.not.allocated (foo)) call abort
  75. if (size (foo).ne.18) call abort
  76. if (any (foo.ne.1)) call abort
  77. deallocate (foo)
  78. if (allocated (foo)) call abort
  79. end
  80. ! { dg-final { cleanup-modules "threadprivate2" } }