Debian Codegraph @

libgomp/testsuite/libgomp.fortran/unroll-7.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-cpp" }
3
4 #ifndef UNROLL_FACTOR
5 #define UNROLL_FACTOR 1
6 #endif
7 module test_functions
8 contains
9 subroutine copy (array1, array2)
10 implicit none
11 integer :: array1(:)
12 integer :: array2(:)
13 integer :: i
14
15 !$omp parallel do private(i)
16 !$omp unroll partial(UNROLL_FACTOR)
17 do i = 1, 100
18 array1(i) = array2(i)
19 end do
20 end subroutine
21
22 subroutine copy2 (array1, array2)
23 implicit none
24
25 integer :: array1(100)
26 integer :: array2(100)
27 integer :: i
28
29 !$omp parallel do private(i)
30 !$omp unroll partial(UNROLL_FACTOR)
31 do i = 0,99
32 array1(i+1) = array2(i+1)
33 end do
34 end subroutine copy2
35
36 subroutine copy3 (array1, array2)
37 implicit none
38
39 integer :: array1(100)
40 integer :: array2(100)
41 integer :: i
42
43 !$omp parallel do lastprivate(i)
44 !$omp unroll partial(UNROLL_FACTOR)
45 do i = -49,50
46 if (i < 0) then
47 array1((-1)*i) = array2((-1)*i)
48 else
49 array1(50+i) = array2(50+i)
50 endif
51 end do
52 end subroutine copy3
53
54 subroutine copy4 (array1, array2)
55 implicit none
56 integer :: array1(:)
57 integer :: array2(:)
58 integer :: i
59
60 !$omp parallel do private(i)
61 !$omp unroll partial(UNROLL_FACTOR)
62 do i = 2, 200, 2
63 array1(i/2) = array2(i/2)
64 end do
65 end subroutine copy4
66
67 subroutine copy5 (array1, array2)
68 implicit none
69 integer :: array1(:)
70 integer :: array2(:)
71 integer :: i
72
73 !$omp parallel do private(i)
74 !$omp unroll partial(UNROLL_FACTOR)
75 do i = 200, 2, -2
76 array1(i/2) = array2(i/2)
77 end do
78 end subroutine
79
80 subroutine copy6 (array1, array2, lower, upper, step)
81 implicit none
82 integer :: array1(:)
83 integer :: array2(:)
84 integer :: lower, upper, step
85 integer :: i
86
87 !$omp parallel do private(i)
88 !$omp unroll partial(UNROLL_FACTOR)
89 do i = lower, upper, step
90 array1 (i) = array2(i)
91 end do
92 end subroutine
93
94 subroutine prepare (array1, array2)
95 implicit none
96 integer :: array1(:)
97 integer :: array2(:)
98
99 array1 = 2
100 array2 = 0
101 end subroutine
102
103 subroutine check_equal (array1, array2)
104 implicit none
105 integer :: array1(:)
106 integer :: array2(:)
107 integer :: i
108
109 do i=1,100
110 if (array1(i) /= array2(i)) then
111 stop 1
112 end if
113 end do
114 end subroutine
115
116 subroutine check_equal_at_steps (array1, array2, lower, upper, step)
117 implicit none
118 integer :: array1(:)
119 integer :: array2(:)
120 integer :: lower, upper, step
121 integer :: i
122
123 do i=lower, upper, step
124 if (array1(i) /= array2(i)) then
125 stop 2
126 end if
127 end do
128 end subroutine
129
130 subroutine check_unchanged_at_non_steps (array1, array2, lower, upper, step)
131 implicit none
132 integer :: array1(:)
133 integer :: array2(:)
134 integer :: lower, upper, step
135 integer :: i, j
136
137 do i=lower, upper,step
138 do j=i,i+step-1
139 if (array2(j) /= 0) then
140 stop 3
141 end if
142 end do
143 end do
144 end subroutine
145 end module test_functions
146
147 program test
148 use test_functions
149 implicit none
150 integer :: array1(100), array2(100)
151
152 call prepare (array1, array2)
153 call copy (array1, array2)
154 call check_equal (array1, array2)
155
156 call prepare (array1, array2)
157 call copy2 (array1, array2)
158 call check_equal (array1, array2)
159
160 call prepare (array1, array2)
161 call copy3 (array1, array2)
162 call check_equal (array1, array2)
163
164 call prepare (array1, array2)
165 call copy4 (array1, array2)
166 call check_equal (array1, array2)
167
168 call prepare (array1, array2)
169 call copy5 (array1, array2)
170 call check_equal (array1, array2)
171
172 call prepare (array1, array2)
173 call copy6 (array1, array2, 1, 100, 5)
174 call check_equal_at_steps (array1, array2, 1, 100, 5)
175 call check_unchanged_at_non_steps (array1, array2, 1, 100, 5)
176
177 call prepare (array1, array2)
178 call copy6 (array1, array2, 1, 50, 5)
179 call check_equal_at_steps (array1, array2, 1, 50, 5)
180 call check_unchanged_at_non_steps (array1, array2, 1, 50, 5)
181
182 call prepare (array1, array2)
183 call copy6 (array1, array2, 3, 18, 7)
184 call check_equal_at_steps (array1, array2, 3 , 18, 7)
185 call check_unchanged_at_non_steps (array1, array2, 3, 18, 7)
186 end program