threadprivate4.f90 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ! { dg-do run }
  2. ! { dg-require-effective-target tls_runtime }
  3. module threadprivate4
  4. integer :: vi
  5. procedure(), pointer :: foo
  6. !$omp threadprivate (foo, vi)
  7. contains
  8. subroutine fn0
  9. vi = 0
  10. end subroutine fn0
  11. subroutine fn1
  12. vi = 1
  13. end subroutine fn1
  14. subroutine fn2
  15. vi = 2
  16. end subroutine fn2
  17. subroutine fn3
  18. vi = 3
  19. end subroutine fn3
  20. end module threadprivate4
  21. use omp_lib
  22. use threadprivate4
  23. integer :: i
  24. logical :: l
  25. procedure(), pointer :: bar1
  26. common /thrc/ bar1
  27. !$omp threadprivate (/thrc/)
  28. procedure(), pointer, save :: bar2
  29. !$omp threadprivate (bar2)
  30. l = .false.
  31. call omp_set_dynamic (.false.)
  32. call omp_set_num_threads (4)
  33. !$omp parallel num_threads (4) reduction (.or.:l) private (i)
  34. i = omp_get_thread_num ()
  35. if (i.eq.0) then
  36. foo => fn0
  37. bar1 => fn0
  38. bar2 => fn0
  39. elseif (i.eq.1) then
  40. foo => fn1
  41. bar1 => fn1
  42. bar2 => fn1
  43. elseif (i.eq.2) then
  44. foo => fn2
  45. bar1 => fn2
  46. bar2 => fn2
  47. else
  48. foo => fn3
  49. bar1 => fn3
  50. bar2 => fn3
  51. end if
  52. vi = -1
  53. !$omp barrier
  54. vi = -1
  55. call foo ()
  56. l=l.or.(vi.ne.i)
  57. vi = -2
  58. call bar1 ()
  59. l=l.or.(vi.ne.i)
  60. vi = -3
  61. call bar2 ()
  62. l=l.or.(vi.ne.i)
  63. vi = -1
  64. !$omp end parallel
  65. if (l) call abort
  66. end
  67. ! { dg-final { cleanup-modules "threadprivate4" } }