omp_parse3.f90 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ! { dg-do run }
  2. ! { dg-require-effective-target tls_runtime }
  3. use omp_lib
  4. common /tlsblock/ x, y
  5. integer :: x, y, z
  6. save z
  7. !$omp threadprivate (/tlsblock/, z)
  8. call test_flush
  9. call test_ordered
  10. call test_threadprivate
  11. contains
  12. subroutine test_flush
  13. integer :: i, j
  14. i = 0
  15. j = 0
  16. !$omp parallel num_threads (4)
  17. if (omp_get_thread_num () .eq. 0) i = omp_get_num_threads ()
  18. if (omp_get_thread_num () .eq. 0) j = j + 1
  19. !$omp flush (i, j)
  20. !$omp barrier
  21. if (omp_get_thread_num () .eq. 1) j = j + 2
  22. !$omp flush
  23. !$omp barrier
  24. if (omp_get_thread_num () .eq. 2) j = j + 3
  25. !$omp flush (i)
  26. !$omp flush (j)
  27. !$omp barrier
  28. if (omp_get_thread_num () .eq. 3) j = j + 4
  29. !$omp end parallel
  30. end subroutine test_flush
  31. subroutine test_ordered
  32. integer :: i, j
  33. integer, dimension (100) :: d
  34. d(:) = -1
  35. !$omp parallel do ordered schedule (dynamic) num_threads (4)
  36. do i = 1, 100, 5
  37. !$omp ordered
  38. d(i) = i
  39. !$omp end ordered
  40. end do
  41. j = 1
  42. do 100 i = 1, 100
  43. if (i .eq. j) then
  44. if (d(i) .ne. i) call abort
  45. j = i + 5
  46. else
  47. if (d(i) .ne. -1) call abort
  48. end if
  49. 100 d(i) = -1
  50. end subroutine test_ordered
  51. subroutine test_threadprivate
  52. common /tlsblock/ x, y
  53. !$omp threadprivate (/tlsblock/)
  54. integer :: i, j, x, y
  55. logical :: m, n
  56. call omp_set_num_threads (4)
  57. call omp_set_dynamic (.false.)
  58. i = -1
  59. x = 6
  60. y = 7
  61. z = 8
  62. n = .false.
  63. m = .false.
  64. !$omp parallel copyin (/tlsblock/, z) reduction (.or.:m) &
  65. !$omp& num_threads (4)
  66. if (omp_get_thread_num () .eq. 0) i = omp_get_num_threads ()
  67. if (x .ne. 6 .or. y .ne. 7 .or. z .ne. 8) call abort
  68. x = omp_get_thread_num ()
  69. y = omp_get_thread_num () + 1024
  70. z = omp_get_thread_num () + 4096
  71. !$omp end parallel
  72. if (x .ne. 0 .or. y .ne. 1024 .or. z .ne. 4096) call abort
  73. !$omp parallel num_threads (4), private (j) reduction (.or.:n)
  74. if (omp_get_num_threads () .eq. i) then
  75. j = omp_get_thread_num ()
  76. if (x .ne. j .or. y .ne. j + 1024 .or. z .ne. j + 4096) &
  77. & call abort
  78. end if
  79. !$omp end parallel
  80. m = m .or. n
  81. n = .false.
  82. !$omp parallel num_threads (4), copyin (z) reduction (.or. : n) &
  83. !$omp&private (j)
  84. if (z .ne. 4096) n = .true.
  85. if (omp_get_num_threads () .eq. i) then
  86. j = omp_get_thread_num ()
  87. if (x .ne. j .or. y .ne. j + 1024) call abort
  88. end if
  89. !$omp end parallel
  90. if (m .or. n) call abort
  91. end subroutine test_threadprivate
  92. end