reduction-6.f90 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ! { dg-do run }
  2. ! { dg-additional-options "-cpp" }
  3. ! { dg-additional-options "-Wopenacc-parallelism" } for testing/documenting
  4. ! aspects of that functionality.
  5. program reduction
  6. implicit none
  7. integer, parameter :: n = 100, n2 = 1000, chunksize = 10
  8. integer :: i, gs1, gs2, ws1, ws2, vs1, vs2, cs1, cs2, hs1, hs2
  9. integer :: j, red, vred
  10. gs1 = 0
  11. gs2 = 0
  12. ws1 = 0
  13. ws2 = 0
  14. vs1 = 0
  15. vs2 = 0
  16. cs1 = 0
  17. cs2 = 0
  18. hs1 = 0
  19. hs2 = 0
  20. !$acc parallel num_gangs (1000)
  21. !$acc loop reduction(+:gs1, gs2) gang
  22. do i = 1, n
  23. gs1 = gs1 + 1
  24. gs2 = gs2 + 2
  25. end do
  26. !$acc end parallel
  27. !$acc parallel num_workers (4) vector_length (32)
  28. ! { dg-warning "region is vector partitioned but does not contain vector partitioned code" "" { target *-*-* } .-1 }
  29. !$acc loop reduction(+:ws1, ws2) worker
  30. do i = 1, n
  31. ws1 = ws1 + 1
  32. ws2 = ws2 + 2
  33. end do
  34. !$acc end parallel
  35. !$acc parallel vector_length (32)
  36. !$acc loop reduction(+:vs1, vs2) vector
  37. do i = 1, n
  38. vs1 = vs1 + 1
  39. vs2 = vs2 + 2
  40. end do
  41. !$acc end parallel
  42. !$acc parallel num_gangs(8) num_workers(4) vector_length(32)
  43. !$acc loop reduction(+:cs1, cs2) gang worker vector
  44. do i = 1, n
  45. cs1 = cs1 + 1
  46. cs2 = cs2 + 2
  47. end do
  48. !$acc end parallel
  49. ! Verify the results on the host
  50. do i = 1, n
  51. hs1 = hs1 + 1
  52. hs2 = hs2 + 2
  53. end do
  54. if (gs1 .ne. hs1) STOP 1
  55. if (gs2 .ne. hs2) STOP 2
  56. if (ws1 .ne. hs1) STOP 3
  57. if (ws2 .ne. hs2) STOP 4
  58. if (vs1 .ne. hs1) STOP 5
  59. if (vs2 .ne. hs2) STOP 6
  60. if (cs1 .ne. hs1) STOP 7
  61. if (cs2 .ne. hs2) STOP 8
  62. ! Nested reductions.
  63. red = 0
  64. vred = 0
  65. !$acc parallel num_gangs(10) vector_length(32)
  66. !$acc loop reduction(+:red) gang
  67. do i = 1, n/chunksize
  68. !$acc loop reduction(+:red) vector
  69. do j = 1, chunksize
  70. red = red + chunksize
  71. end do
  72. end do
  73. !$acc end parallel
  74. do i = 1, n/chunksize
  75. do j = 1, chunksize
  76. vred = vred + chunksize
  77. end do
  78. end do
  79. if (red .ne. vred) STOP 9
  80. end program reduction