2
2
3
3
module test_logicalloc
4
4
use stdlib_array, only : trueloc, falseloc
5
- use stdlib_string_type, only : string_type, len
5
+ use stdlib_kinds, only : dp, i8 = > int64
6
+ use stdlib_strings, only : to_string
6
7
use testdrive, only : new_unittest, unittest_type, error_type, check
7
8
implicit none
8
9
private
@@ -75,23 +76,31 @@ subroutine test_trueloc_where(error)
75
76
76
77
integer :: ndim
77
78
real , allocatable :: avec(:), bvec(:), cvec(:)
79
+ real (dp) :: tl, tw
78
80
81
+ tl = 0.0_dp
82
+ tw = 0.0_dp
79
83
do ndim = 100 , 12000 , 100
80
84
allocate (avec(ndim))
81
85
82
86
call random_number (avec)
83
87
avec(:) = avec - 0.5
84
88
85
89
bvec = avec
90
+ tl = tl - timing()
86
91
bvec(trueloc(bvec > 0 )) = 0.0
92
+ tl = tl + timing()
87
93
88
94
cvec = avec
95
+ tw = tw - timing()
89
96
where (cvec > 0 ) cvec = 0.0
97
+ tw = tw + timing()
90
98
91
99
call check(error, all (bvec == cvec))
92
100
deallocate (avec, bvec, cvec)
93
101
if (allocated (error)) exit
94
102
end do
103
+ call report(" trueloc" , tl, " where" , tw)
95
104
end subroutine test_trueloc_where
96
105
97
106
subroutine test_trueloc_merge (error )
@@ -100,23 +109,31 @@ subroutine test_trueloc_merge(error)
100
109
101
110
integer :: ndim
102
111
real , allocatable :: avec(:), bvec(:), cvec(:)
112
+ real (dp) :: tl, tm
103
113
114
+ tl = 0.0_dp
115
+ tm = 0.0_dp
104
116
do ndim = 100 , 12000 , 100
105
117
allocate (avec(ndim))
106
118
107
119
call random_number (avec)
108
120
avec(:) = avec - 0.5
109
121
110
122
bvec = avec
123
+ tl = tl - timing()
111
124
bvec(trueloc(bvec > 0 )) = 0.0
125
+ tl = tl + timing()
112
126
113
127
cvec = avec
128
+ tm = tm - timing()
114
129
cvec(:) = merge (0.0 , cvec, cvec > 0 )
130
+ tm = tm + timing()
115
131
116
132
call check(error, all (bvec == cvec))
117
133
deallocate (avec, bvec, cvec)
118
134
if (allocated (error)) exit
119
135
end do
136
+ call report(" trueloc" , tl, " merge" , tm)
120
137
end subroutine test_trueloc_merge
121
138
122
139
subroutine test_falseloc_empty (error )
@@ -166,23 +183,31 @@ subroutine test_falseloc_where(error)
166
183
167
184
integer :: ndim
168
185
real , allocatable :: avec(:), bvec(:), cvec(:)
186
+ real (dp) :: tl, tw
169
187
188
+ tl = 0.0_dp
189
+ tw = 0.0_dp
170
190
do ndim = 100 , 12000 , 100
171
191
allocate (avec(ndim))
172
192
173
193
call random_number (avec)
174
194
avec(:) = avec - 0.5
175
195
176
196
bvec = avec
197
+ tl = tl - timing()
177
198
bvec(falseloc(bvec > 0 )) = 0.0
199
+ tl = tl + timing()
178
200
179
201
cvec = avec
202
+ tw = tw - timing()
180
203
where (.not. (cvec > 0 )) cvec = 0.0
204
+ tw = tw + timing()
181
205
182
206
call check(error, all (bvec == cvec))
183
207
deallocate (avec, bvec, cvec)
184
208
if (allocated (error)) exit
185
209
end do
210
+ call report(" falseloc" , tl, " where" , tw)
186
211
end subroutine test_falseloc_where
187
212
188
213
subroutine test_falseloc_merge (error )
@@ -191,25 +216,54 @@ subroutine test_falseloc_merge(error)
191
216
192
217
integer :: ndim
193
218
real , allocatable :: avec(:), bvec(:), cvec(:)
219
+ real (dp) :: tl, tm
194
220
221
+ tl = 0.0_dp
222
+ tm = 0.0_dp
195
223
do ndim = 100 , 12000 , 100
196
224
allocate (avec(ndim))
197
225
198
226
call random_number (avec)
199
227
avec(:) = avec - 0.5
200
228
201
229
bvec = avec
230
+ tl = tl - timing()
202
231
bvec(falseloc(bvec > 0 )) = 0.0
232
+ tl = tl + timing()
203
233
204
234
cvec = avec
235
+ tm = tm - timing()
205
236
cvec(:) = merge (cvec, 0.0 , cvec > 0 )
237
+ tm = tm + timing()
206
238
207
239
call check(error, all (bvec == cvec))
208
240
deallocate (avec, bvec, cvec)
209
241
if (allocated (error)) exit
210
242
end do
243
+ call report(" falseloc" , tl, " merge" , tm)
211
244
end subroutine test_falseloc_merge
212
245
246
+ subroutine report (l1 , t1 , l2 , t2 )
247
+ character (len=* ), intent (in ) :: l1, l2
248
+ real (dp), intent (in ) :: t1, t2
249
+ character (len=* ), parameter :: fmt = " f6.4"
250
+
251
+ ! $omp critical
252
+ print ' (2x, "[Timing]", *(1x, g0))' , &
253
+ l1// " :" , to_string(t1, fmt)// " s" , &
254
+ l2// " :" , to_string(t2, fmt)// " s" , &
255
+ " ratio:" , to_string(t1/ t2, " f4.1" )
256
+ ! $omp end critical
257
+ end subroutine report
258
+
259
+ function timing () result(time)
260
+ real (dp) :: time
261
+
262
+ integer (i8) :: time_count, time_rate, time_max
263
+ call system_clock (time_count, time_rate, time_max)
264
+ time = real (time_count, dp)/ real (time_rate, dp)
265
+ end function timing
266
+
213
267
end module test_logicalloc
214
268
215
269
0 commit comments