simd3.f90 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ! { dg-do run }
  2. ! { dg-additional-options "-msse2" { target sse2_runtime } }
  3. ! { dg-additional-options "-mavx" { target avx_runtime } }
  4. integer :: a(1024), b(1024), k, m, i, s, t
  5. k = 4
  6. m = 2
  7. t = 1
  8. do i = 1, 1024
  9. a(i) = i - 513
  10. b(i) = modulo (i - 52, 39)
  11. if (i.lt.52.and.b(i).ne.0) b(i) = b(i) - 39
  12. end do
  13. s = foo (b)
  14. do i = 1, 1024
  15. if (a(i).ne.((i - 513) * b(i))) call abort
  16. if (i.lt.52.and.modulo (i - 52, 39).ne.0) then
  17. if (b(i).ne.(modulo (i - 52, 39) - 39)) call abort
  18. else
  19. if (b(i).ne.(modulo (i - 52, 39))) call abort
  20. end if
  21. a(i) = i - 513
  22. end do
  23. if (k.ne.(4 + 3 * 1024).or.s.ne.1596127) call abort
  24. k = 4
  25. m = 2
  26. t = 1
  27. s = bar (b)
  28. do i = 1, 1024
  29. if (a(i).ne.((i - 513) * b(i))) call abort
  30. if (i.lt.52.and.modulo (i - 52, 39).ne.0) then
  31. if (b(i).ne.(modulo (i - 52, 39) - 39)) call abort
  32. else
  33. if (b(i).ne.(modulo (i - 52, 39))) call abort
  34. end if
  35. a(i) = i - 513
  36. end do
  37. if (k.ne.(4 + 3 * 1024).or.s.ne.1596127) call abort
  38. k = 4
  39. m = 2
  40. t = 1
  41. s = baz (b)
  42. do i = 1, 1024
  43. if (a(i).ne.((i - 513) * b(i))) call abort
  44. if (i.lt.52.and.modulo (i - 52, 39).ne.0) then
  45. if (b(i).ne.(modulo (i - 52, 39) - 39)) call abort
  46. else
  47. if (b(i).ne.(modulo (i - 52, 39))) call abort
  48. end if
  49. end do
  50. if (k.ne.(4 + 3 * 1024).or.s.ne.1596127) call abort
  51. contains
  52. function foo (p)
  53. integer :: p(1024), u, v, i, s, foo
  54. s = 0
  55. !$omp parallel
  56. !$omp do simd linear(k : m + 1) reduction(+: s) lastprivate(u, v) &
  57. !$omp & schedule (static, 32)
  58. do i = 1, 1024
  59. a(i) = a(i) * p(i)
  60. u = p(i) + k
  61. k = k + m + 1
  62. v = p(i) + k
  63. s = s + p(i) + k
  64. end do
  65. !$omp end do simd
  66. !$omp end parallel
  67. if (i.ne.1025) call abort
  68. if (u.ne.(36 + 4 + 3 * 1023).or.v.ne.(36 + 4 + 3 * 1024)) call abort
  69. foo = s
  70. end function foo
  71. function bar (p)
  72. integer :: p(1024), u, v, i, s, bar
  73. s = 0
  74. !$omp parallel
  75. !$omp do simd linear(k : m + 1) reduction(+: s) lastprivate(u, v) &
  76. !$omp & schedule (dynamic, 32)
  77. do i = 1, 1024, t
  78. a(i) = a(i) * p(i)
  79. u = p(i) + k
  80. k = k + m + 1
  81. v = p(i) + k
  82. s = s + p(i) + k
  83. end do
  84. !$omp end do simd
  85. !$omp endparallel
  86. if (i.ne.1025) call abort
  87. if (u.ne.(36 + 4 + 3 * 1023).or.v.ne.(36 + 4 + 3 * 1024)) call abort
  88. bar = s
  89. end function bar
  90. function baz (p)
  91. integer :: p(1024), u, v, i, s, baz
  92. s = 0
  93. !$omp parallel
  94. !$omp do simd linear(k : m + 1) reduction(+: s) lastprivate(u, v) &
  95. !$omp & linear(i : t) schedule (static, 8)
  96. do i = 1, 1024, t
  97. a(i) = a(i) * p(i)
  98. u = p(i) + k
  99. k = k + m + 1
  100. v = p(i) + k
  101. s = s + p(i) + k
  102. end do
  103. !$omp end parallel
  104. if (i.ne.1025) call abort
  105. if (u.ne.(36 + 4 + 3 * 1023).or.v.ne.(36 + 4 + 3 * 1024)) call abort
  106. baz = s
  107. end function baz
  108. end