alloc-comp-1.f90 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. ! { dg-do run }
  2. ! Don't cycle by default through all options, just test -O0 and -O2,
  3. ! as this is quite large test.
  4. ! { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } }
  5. module m
  6. type dl
  7. integer :: a, b
  8. integer, allocatable :: c(:,:)
  9. integer :: d, e
  10. integer, allocatable :: f
  11. end type
  12. type dt
  13. integer :: g
  14. type (dl), allocatable :: h(:)
  15. integer :: i
  16. type (dl) :: j(2, 2)
  17. type (dl), allocatable :: k
  18. end type
  19. contains
  20. subroutine ver_dl (obj, val, c, cl1, cu1, cl2, cu2, f)
  21. type (dl), intent (in) :: obj
  22. integer, intent (in) :: val, cl1, cu1, cl2, cu2
  23. logical, intent (in) :: c, f
  24. if ((c .neqv. allocated (obj%c)) .or. (f .neqv. allocated (obj%f))) call abort
  25. if (c) then
  26. if (lbound (obj%c, 1) /= cl1 .or. ubound (obj%c, 1) /= cu1) call abort
  27. if (lbound (obj%c, 2) /= cl2 .or. ubound (obj%c, 2) /= cu2) call abort
  28. end if
  29. if (val /= 0) then
  30. if (obj%a /= val .or. obj%b /= val) call abort
  31. if (obj%d /= val .or. obj%e /= val) call abort
  32. if (c) then
  33. if (any (obj%c /= val)) call abort
  34. end if
  35. if (f) then
  36. if (obj%f /= val) call abort
  37. end if
  38. end if
  39. end subroutine ver_dl
  40. subroutine ver_dt (obj, val, h, hl, hu, k, c, cl1, cu1, cl2, cu2, f)
  41. type (dt), intent (in) :: obj
  42. integer, intent (in) :: val, hl, hu, cl1, cu1, cl2, cu2
  43. logical, intent (in) :: h, k, c, f
  44. integer :: i, j
  45. if ((h .neqv. allocated (obj%h)) .or. (k .neqv. allocated (obj%k))) call abort
  46. if (h) then
  47. if (lbound (obj%h, 1) /= hl .or. ubound (obj%h, 1) /= hu) call abort
  48. do i = hl, hu
  49. call ver_dl (obj%h(i), val, c, cl1, cu1, cl2, cu2, f)
  50. end do
  51. end if
  52. do i = 1, 2
  53. do j = 1, 2
  54. call ver_dl (obj%j(i, j), val, c, cl1, cu1, cl2, cu2, f)
  55. end do
  56. end do
  57. if (k) call ver_dl (obj%k, val, c, cl1, cu1, cl2, cu2, f)
  58. if (val /= 0) then
  59. if (obj%g /= val .or. obj%i /= val) call abort
  60. end if
  61. end subroutine ver_dt
  62. subroutine alloc_dl (obj, val, c, cl1, cu1, cl2, cu2, f)
  63. type (dl), intent (inout) :: obj
  64. integer, intent (in) :: val, cl1, cu1, cl2, cu2
  65. logical, intent (in) :: c, f
  66. if (val /= 0) then
  67. obj%a = val
  68. obj%b = val
  69. obj%d = val
  70. obj%e = val
  71. end if
  72. if (allocated (obj%c)) deallocate (obj%c)
  73. if (c) then
  74. allocate (obj%c(cl1:cu1, cl2:cu2))
  75. if (val /= 0) obj%c = val
  76. end if
  77. if (f) then
  78. if (.not.allocated (obj%f)) allocate (obj%f)
  79. if (val /= 0) obj%f = val
  80. else
  81. if (allocated (obj%f)) deallocate (obj%f)
  82. end if
  83. end subroutine alloc_dl
  84. subroutine alloc_dt (obj, val, h, hl, hu, k, c, cl1, cu1, cl2, cu2, f)
  85. type (dt), intent (inout) :: obj
  86. integer, intent (in) :: val, hl, hu, cl1, cu1, cl2, cu2
  87. logical, intent (in) :: h, k, c, f
  88. integer :: i, j
  89. if (val /= 0) then
  90. obj%g = val
  91. obj%i = val
  92. end if
  93. if (allocated (obj%h)) deallocate (obj%h)
  94. if (h) then
  95. allocate (obj%h(hl:hu))
  96. do i = hl, hu
  97. call alloc_dl (obj%h(i), val, c, cl1, cu1, cl2, cu2, f)
  98. end do
  99. end if
  100. do i = 1, 2
  101. do j = 1, 2
  102. call alloc_dl (obj%j(i, j), val, c, cl1, cu1, cl2, cu2, f)
  103. end do
  104. end do
  105. if (k) then
  106. if (.not.allocated (obj%k)) allocate (obj%k)
  107. call alloc_dl (obj%k, val, c, cl1, cu1, cl2, cu2, f)
  108. else
  109. if (allocated (obj%k)) deallocate (obj%k)
  110. end if
  111. end subroutine alloc_dt
  112. end module m
  113. use m
  114. type (dt) :: y
  115. call foo (y)
  116. contains
  117. subroutine foo (y)
  118. use m
  119. type (dt) :: x, y, z(-3:-3,2:3)
  120. logical, parameter :: F = .false.
  121. logical, parameter :: T = .true.
  122. logical :: l
  123. call ver_dt (x, 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  124. call ver_dt (y, 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  125. call ver_dt (z(-3,2), 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  126. call ver_dt (z(-3,3), 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  127. !$omp parallel private (x, y, z)
  128. call ver_dt (x, 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  129. call alloc_dt (x, 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  130. call ver_dt (x, 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  131. call ver_dt (y, 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  132. call alloc_dt (y, 14, T, 3, 4, F, T, 1, 1, 2, 4, T)
  133. call ver_dt (y, 14, T, 3, 4, F, T, 1, 1, 2, 4, T)
  134. call ver_dt (z(-3,2), 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  135. call alloc_dt (z(-3,2), 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  136. call ver_dt (z(-3,2), 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  137. call ver_dt (z(-3,3), 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  138. call alloc_dt (z(-3,3), 14, T, 3, 4, F, T, 1, 1, 2, 4, T)
  139. call ver_dt (z(-3,3), 14, T, 3, 4, F, T, 1, 1, 2, 4, T)
  140. !$omp end parallel
  141. call ver_dt (x, 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  142. call alloc_dt (x, 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  143. call ver_dt (y, 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  144. call alloc_dt (y, 14, T, 3, 4, F, T, 1, 1, 2, 4, T)
  145. call ver_dt (z(-3,2), 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  146. call alloc_dt (z(-3,2), 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  147. call ver_dt (z(-3,3), 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  148. call alloc_dt (z(-3,3), 14, T, 3, 4, F, T, 1, 1, 2, 4, T)
  149. !$omp parallel private (x, y, z)
  150. call ver_dt (x, 0, T, -3, -1, T, T, -1, -1, 2, 3, T)
  151. call ver_dt (y, 0, T, 3, 4, F, T, 1, 1, 2, 4, T)
  152. deallocate (x%h, x%k)
  153. deallocate (y%h)
  154. allocate (y%k)
  155. call ver_dt (z(-3,2), 0, T, -3, -1, T, T, -1, -1, 2, 3, T)
  156. call ver_dt (z(-3,3), 0, T, 3, 4, F, T, 1, 1, 2, 4, T)
  157. deallocate (z(-3,2)%h, z(-3,2)%k)
  158. deallocate (z(-3,3)%h)
  159. allocate (z(-3,3)%k)
  160. !$omp end parallel
  161. call alloc_dt (x, 5, T, 1, 2, F, T, 2, 3, -2, -2, F)
  162. call alloc_dt (y, 15, F, 0, 0, T, T, 2, 2, 2, 2, T)
  163. call alloc_dt (z(-3,2), 5, T, 1, 2, F, T, 2, 3, -2, -2, F)
  164. call alloc_dt (z(-3,3), 15, F, 0, 0, T, T, 2, 2, 2, 2, T)
  165. !$omp parallel firstprivate (x, y, z)
  166. call ver_dt (x, 5, T, 1, 2, F, T, 2, 3, -2, -2, F)
  167. call alloc_dt (x, 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  168. call ver_dt (x, 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  169. call ver_dt (y, 15, F, 0, 0, T, T, 2, 2, 2, 2, T)
  170. call alloc_dt (y, 4, T, 3, 4, T, T, 1, 1, 2, 4, T)
  171. call ver_dt (y, 4, T, 3, 4, T, T, 1, 1, 2, 4, T)
  172. call ver_dt (z(-3,2), 5, T, 1, 2, F, T, 2, 3, -2, -2, F)
  173. call alloc_dt (z(-3,2), 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  174. call ver_dt (z(-3,2), 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  175. call ver_dt (z(-3,3), 15, F, 0, 0, T, T, 2, 2, 2, 2, T)
  176. call alloc_dt (z(-3,3), 4, T, 3, 4, T, T, 1, 1, 2, 4, T)
  177. call ver_dt (z(-3,3), 4, T, 3, 4, T, T, 1, 1, 2, 4, T)
  178. !$omp end parallel
  179. call ver_dt (x, 5, T, 1, 2, F, T, 2, 3, -2, -2, F)
  180. call alloc_dt (x, 4, F, 0, 0, F, F, 0, 0, 0, 0, F)
  181. call ver_dt (y, 15, F, 0, 0, T, T, 2, 2, 2, 2, T)
  182. call alloc_dt (y, 16, F, 0, 0, F, F, 0, 0, 0, 0, F)
  183. call ver_dt (z(-3,2), 5, T, 1, 2, F, T, 2, 3, -2, -2, F)
  184. call alloc_dt (z(-3,2), 4, F, 0, 0, F, F, 0, 0, 0, 0, F)
  185. call ver_dt (z(-3,3), 15, F, 0, 0, T, T, 2, 2, 2, 2, T)
  186. call alloc_dt (z(-3,3), 16, F, 0, 0, F, F, 0, 0, 0, 0, F)
  187. !$omp parallel firstprivate (x, y, z)
  188. call ver_dt (x, 4, F, 0, 0, F, F, 0, 0, 0, 0, F)
  189. call alloc_dt (x, 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  190. call ver_dt (x, 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  191. call ver_dt (y, 16, F, 0, 0, F, F, 0, 0, 0, 0, F)
  192. call alloc_dt (y, 17, T, 1, 2, F, T, 2, 2, 3, 3, F)
  193. call ver_dt (y, 17, T, 1, 2, F, T, 2, 2, 3, 3, F)
  194. call ver_dt (z(-3,2), 4, F, 0, 0, F, F, 0, 0, 0, 0, F)
  195. call alloc_dt (z(-3,2), 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  196. call ver_dt (z(-3,2), 4, T, -3, -1, T, T, -1, -1, 2, 3, T)
  197. call ver_dt (z(-3,3), 16, F, 0, 0, F, F, 0, 0, 0, 0, F)
  198. call alloc_dt (z(-3,3), 17, T, 1, 2, F, T, 2, 2, 3, 3, F)
  199. call ver_dt (z(-3,3), 17, T, 1, 2, F, T, 2, 2, 3, 3, F)
  200. !$omp end parallel
  201. call ver_dt (x, 4, F, 0, 0, F, F, 0, 0, 0, 0, F)
  202. call ver_dt (y, 16, F, 0, 0, F, F, 0, 0, 0, 0, F)
  203. call alloc_dt (y, 18, T, 0, 1, T, T, 0, 1, 0, 1, T)
  204. call ver_dt (z(-3,2), 4, F, 0, 0, F, F, 0, 0, 0, 0, F)
  205. call ver_dt (z(-3,3), 16, F, 0, 0, F, F, 0, 0, 0, 0, F)
  206. call alloc_dt (z(-3,3), 18, T, 0, 1, T, T, 0, 1, 0, 1, T)
  207. l = F
  208. !$omp parallel sections lastprivate (x, y, z) firstprivate (l)
  209. !$omp section
  210. if (l) then
  211. call ver_dt (x, 9, T, 1, 1, F, F, 0, 0, 0, 0, T)
  212. call ver_dt (y, 21, F, 0, 0, T, T, 1, 2, 3, 4, T)
  213. call ver_dt (z(-3,2), 9, T, 1, 1, F, F, 0, 0, 0, 0, T)
  214. call ver_dt (z(-3,3), 21, F, 0, 0, T, T, 1, 2, 3, 4, T)
  215. else
  216. call ver_dt (x, 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  217. call ver_dt (y, 0, T, 0, 1, T, T, 0, 1, 0, 1, T)
  218. call ver_dt (z(-3,2), 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  219. call ver_dt (z(-3,3), 0, T, 0, 1, T, T, 0, 1, 0, 1, T)
  220. end if
  221. l = T
  222. call alloc_dt (x, 7, T, 1, 1, T, T, 1, 2, 3, 3, T)
  223. call ver_dt (x, 7, T, 1, 1, T, T, 1, 2, 3, 3, T)
  224. call alloc_dt (y, 20, T, 0, 0, F, T, 2, 2, 3, 4, F)
  225. call ver_dt (y, 20, T, 0, 0, F, T, 2, 2, 3, 4, F)
  226. call alloc_dt (z(-3,2), 7, T, 1, 1, T, T, 1, 2, 3, 3, T)
  227. call ver_dt (z(-3,2), 7, T, 1, 1, T, T, 1, 2, 3, 3, T)
  228. call alloc_dt (z(-3,3), 20, T, 0, 0, F, T, 2, 2, 3, 4, F)
  229. call ver_dt (z(-3,3), 20, T, 0, 0, F, T, 2, 2, 3, 4, F)
  230. !$omp section
  231. if (l) then
  232. call ver_dt (x, 7, T, 1, 1, T, T, 1, 2, 3, 3, T)
  233. call ver_dt (y, 20, T, 0, 0, F, T, 2, 2, 3, 4, F)
  234. call ver_dt (z(-3,2), 7, T, 1, 1, T, T, 1, 2, 3, 3, T)
  235. call ver_dt (z(-3,3), 20, T, 0, 0, F, T, 2, 2, 3, 4, F)
  236. else
  237. call ver_dt (x, 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  238. call ver_dt (y, 0, T, 0, 1, T, T, 0, 1, 0, 1, T)
  239. call ver_dt (z(-3,2), 0, F, 0, 0, F, F, 0, 0, 0, 0, F)
  240. call ver_dt (z(-3,3), 0, T, 0, 1, T, T, 0, 1, 0, 1, T)
  241. end if
  242. l = T
  243. call alloc_dt (x, 9, T, 1, 1, F, F, 0, 0, 0, 0, T)
  244. call ver_dt (x, 9, T, 1, 1, F, F, 0, 0, 0, 0, T)
  245. call alloc_dt (y, 21, F, 0, 0, T, T, 1, 2, 3, 4, T)
  246. call ver_dt (y, 21, F, 0, 0, T, T, 1, 2, 3, 4, T)
  247. call alloc_dt (z(-3,2), 9, T, 1, 1, F, F, 0, 0, 0, 0, T)
  248. call ver_dt (z(-3,2), 9, T, 1, 1, F, F, 0, 0, 0, 0, T)
  249. call alloc_dt (z(-3,3), 21, F, 0, 0, T, T, 1, 2, 3, 4, T)
  250. call ver_dt (z(-3,3), 21, F, 0, 0, T, T, 1, 2, 3, 4, T)
  251. !$omp section
  252. !$omp end parallel sections
  253. call ver_dt (x, 9, T, 1, 1, F, F, 0, 0, 0, 0, T)
  254. call ver_dt (y, 21, F, 0, 0, T, T, 1, 2, 3, 4, T)
  255. call ver_dt (z(-3,2), 9, T, 1, 1, F, F, 0, 0, 0, 0, T)
  256. call ver_dt (z(-3,3), 21, F, 0, 0, T, T, 1, 2, 3, 4, T)
  257. !$omp parallel sections lastprivate (x, y, z) firstprivate (l)
  258. !$omp section
  259. if (l) then
  260. call ver_dt (x, 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  261. call ver_dt (y, 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  262. call ver_dt (z(-3,2), 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  263. call ver_dt (z(-3,3), 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  264. else
  265. call ver_dt (x, 0, T, 1, 1, F, F, 0, 0, 0, 0, T)
  266. call ver_dt (y, 0, F, 0, 0, T, T, 1, 2, 3, 4, T)
  267. call ver_dt (z(-3,2), 0, T, 1, 1, F, F, 0, 0, 0, 0, T)
  268. call ver_dt (z(-3,3), 0, F, 0, 0, T, T, 1, 2, 3, 4, T)
  269. end if
  270. l = T
  271. call alloc_dt (x, 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  272. call ver_dt (x, 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  273. call alloc_dt (y, 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  274. call ver_dt (y, 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  275. call alloc_dt (z(-3,2), 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  276. call ver_dt (z(-3,2), 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  277. call alloc_dt (z(-3,3), 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  278. call ver_dt (z(-3,3), 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  279. !$omp section
  280. if (l) then
  281. call ver_dt (x, 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  282. call ver_dt (y, 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  283. call ver_dt (z(-3,2), 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  284. call ver_dt (z(-3,3), 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  285. else
  286. call ver_dt (x, 0, T, 1, 1, F, F, 0, 0, 0, 0, T)
  287. call ver_dt (y, 0, F, 0, 0, T, T, 1, 2, 3, 4, T)
  288. call ver_dt (z(-3,2), 0, T, 1, 1, F, F, 0, 0, 0, 0, T)
  289. call ver_dt (z(-3,3), 0, F, 0, 0, T, T, 1, 2, 3, 4, T)
  290. end if
  291. l = T
  292. call alloc_dt (x, 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  293. call ver_dt (x, 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  294. call alloc_dt (y, 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  295. call ver_dt (y, 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  296. call alloc_dt (z(-3,2), 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  297. call ver_dt (z(-3,2), 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  298. call alloc_dt (z(-3,3), 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  299. call ver_dt (z(-3,3), 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  300. !$omp section
  301. !$omp end parallel sections
  302. call ver_dt (x, 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  303. call ver_dt (y, 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  304. call ver_dt (z(-3,2), 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  305. call ver_dt (z(-3,3), 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  306. !$omp parallel private (x, y, z)
  307. call ver_dt (x, 0, F, 0, 0, T, T, -1, -1, -1, -1, T)
  308. call ver_dt (y, 0, T, 0, 1, T, T, 2, 2, 2, 2, F)
  309. call ver_dt (z(-3,2), 0, F, 0, 0, T, T, -1, -1, -1, -1, T)
  310. call ver_dt (z(-3,3), 0, T, 0, 1, T, T, 2, 2, 2, 2, F)
  311. !$omp single
  312. call alloc_dt (x, 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  313. call alloc_dt (y, 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  314. call alloc_dt (z(-3,2), 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  315. call alloc_dt (z(-3,3), 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  316. !$omp end single copyprivate (x, y, z)
  317. call ver_dt (x, 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  318. call ver_dt (y, 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  319. call ver_dt (z(-3,2), 3, F, 0, 0, T, T, 0, 1, 0, 1, F)
  320. call ver_dt (z(-3,3), 22, T, 5, 5, F, T, 2, 3, 2, 2, T)
  321. !$omp end parallel
  322. call ver_dt (x, 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  323. call ver_dt (y, 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  324. call ver_dt (z(-3,2), 5, F, 0, 0, T, T, -1, -1, -1, -1, T)
  325. call ver_dt (z(-3,3), 23, T, 0, 1, T, T, 2, 2, 2, 2, F)
  326. end subroutine foo
  327. end