/[eiffelstudio]/branches/eth/eve/benchmarks/scoop/scoop_thresh/main.e
ViewVC logotype

Contents of /branches/eth/eve/benchmarks/scoop/scoop_thresh/main.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93415 - (show annotations)
Sun Nov 17 16:05:44 2013 UTC (5 years, 10 months ago) by wests
File size: 6735 byte(s)
Updating scoop benchmarks to improve speed, increase test case size.

1 -- thresh: histogram thresholding
2 --
3 -- input:
4 -- matrix: the integer matrix to be thresholded
5 -- nrows, ncols: the number of rows and cols
6 -- percent: the percentage of cells to retain
7 --
8 -- output:
9 -- mask: a boolean matrix filled with true for cells kept
10
11 class MAIN
12 inherit ARGUMENTS
13 create make
14 feature
15 make
16 local
17 nrows, ncols, percent: INTEGER
18 mask: ARRAY2[INTEGER]
19 in: PLAIN_TEXT_FILE
20 file_name: STRING
21 i, j: INTEGER
22 do
23 file_name := separate_character_option_value ('i')
24 is_bench := index_of_word_option ("bench") > 0
25
26 create in.make_open_read (file_name)
27 in.read_integer
28 nrows := in.last_integer
29
30 in.read_integer
31 ncols := in.last_integer
32
33 create matrix.make_with_content (nrows, ncols, is_bench)
34 create histogram.make_filled(0, 0, 100)
35 create accum.make_filled (0, 1, 1)
36
37 in.read_integer
38 percent := in.last_integer
39
40 mask := thresh (nrows, ncols, percent)
41
42 if not is_bench then
43 from i := 1
44 until i > nrows
45 loop
46 from j := 1
47 until j > ncols
48 loop
49 print (mask[i,j].out + " ")
50 j := j + 1
51 end
52 print ("%N")
53 i := i + 1
54 end
55 end
56 end
57
58 thresh(nrows, ncols: INTEGER;
59 percent: INTEGER;): ARRAY2 [INTEGER]
60 local
61 threshold: INTEGER
62 do
63 reduce2d (nrows, ncols)
64
65 threshold := calculate_threshold (nrows, ncols, percent, accum, histogram)
66
67 -- parallel for on matrix
68 Result := parfor(nrows, ncols, threshold)
69 end
70
71 reduce2d (nrows, ncols: INTEGER)
72 local
73 worker: separate REDUCE2D_WORKER
74 workers: LINKED_LIST [separate REDUCE2D_WORKER]
75 start, height, i: INTEGER
76 do
77 create workers.make
78
79 from
80 start := 0
81 i := 0
82 until i >= num_workers
83 loop
84 height := (nrows - start) // (num_workers - i)
85
86 if height > 0 then
87 create worker.make_with_filter
88 (start + 1
89 , start + height
90 , ncols
91 , matrix
92 , accum
93 , histogram)
94
95 workers.extend(worker)
96 end
97
98 start := start + height
99 i := i + 1
100 end
101 -- parallel for on rows
102 workers_reduce_live (workers)
103
104 -- join workers
105 workers_reduce_join (workers)
106 end
107
108 calculate_threshold (nrows, ncols, percent: INTEGER;
109 a_accum: separate ARRAY [INTEGER];
110 a_histogram: separate ARRAY [INTEGER]): INTEGER
111 require
112 a_accum.generator /= Void and a_histogram.generator /= Void
113 local
114 count: INTEGER
115 nmax: INTEGER
116 threshold: INTEGER
117 prefixsum: INTEGER
118 i: INTEGER
119 h: INTEGER
120 do
121 nmax := a_accum.item (1)
122 count := (nrows * ncols * percent) // 100
123
124 prefixsum := 0
125 threshold := nmax
126
127 from i := nmax until not(i >= 0 and prefixsum <= count) loop
128 h := a_histogram.item (i)
129 prefixsum := prefixsum + h
130 threshold := i;
131 i := i - 1
132 end
133
134 Result := threshold
135 end
136
137 -- parallel for on matrix
138 parfor(nrows, ncols: INTEGER;
139 threshold: INTEGER): ARRAY2 [INTEGER]
140 local
141 worker: separate PARFOR_WORKER
142 workers: LINKED_LIST[separate PARFOR_WORKER]
143 i, start, height: INTEGER
144 do
145 create workers.make
146 create shared.make_filled (0, nrows, ncols)
147
148 from
149 start := 0
150 i := 0
151 until i >= num_workers
152 loop
153 height := (nrows - start) // (num_workers - i)
154
155 if height > 0 then
156 create worker.make
157 (start + 1
158 , start + height
159 , ncols
160 , matrix
161 , threshold)
162
163 workers.extend(worker)
164 end
165
166
167 start := start + height
168 i := i + 1
169 end
170
171 -- parallel for on rows
172 workers_parfor_live (workers)
173
174 -- join workers
175 workers_parfor_join (workers)
176
177 Result := get_vector (nrows, ncols, workers)
178 end
179
180 get_vector (nrows, ncols: INTEGER;
181 workers: LIST [separate PARFOR_WORKER]): ARRAY2 [INTEGER]
182 do
183 create Result.make (nrows, ncols)
184 across workers as wc loop
185 get_sub_vector (nrows, ncols, Result, wc.item)
186 end
187 end
188
189 get_sub_vector (nrows, ncols: INTEGER;
190 arr: ARRAY2 [INTEGER];
191 worker: separate PARFOR_WORKER)
192 local
193 i, j: INTEGER
194 do
195 from i := worker.start
196 until i > worker.final
197 loop
198 from j := 1
199 until j > ncols
200 loop
201 arr [i, j] := worker.get (i, j)
202 j := j + 1
203 end
204 i := i + 1
205 end
206 end
207
208
209 fetch_matrix (nrows, ncols: INTEGER;
210 a_array: separate ARRAY2[INTEGER]): ARRAY2 [INTEGER]
211 local
212 i, j: INTEGER
213 do
214 create Result.make_filled (0, nrows, ncols)
215
216 from i := 1
217 until i > nrows
218 loop
219 from j := 1
220 until j > ncols
221 loop
222 Result [i, j] := a_array.item (i, j)
223 j := j + 1
224 end
225 i := i + 1
226 end
227 end
228
229 feature {NONE}
230 is_bench: BOOLEAN
231
232 matrix: separate MATRIX_ARRAY
233 shared: separate ARRAY2[INTEGER]
234 accum: separate ARRAY [INTEGER]
235 histogram: separate ARRAY[INTEGER]
236
237 num_workers: INTEGER = 32
238
239 join_reduce (s: separate REDUCE2D_WORKER)
240 require
241 s.generator /= Void
242 do
243 end
244
245 join_parfor (s: separate PARFOR_WORKER)
246 require
247 s.generator /= Void
248 do
249 end
250
251
252 workers_reduce_live (workers: LINKED_LIST [separate REDUCE2D_WORKER])
253 do
254 from workers.start
255 until workers.after
256 loop
257 live_reduce (workers.item)
258 workers.forth
259 end
260 end
261
262 workers_reduce_join (workers: LINKED_LIST [separate REDUCE2D_WORKER])
263 do
264 from workers.start
265 until workers.after
266 loop
267 join_reduce (workers.item)
268 workers.forth
269 end
270 end
271
272 live_reduce (worker: separate REDUCE2D_WORKER)
273 do
274 worker.live
275 end
276
277 workers_parfor_live (workers: LINKED_LIST [separate PARFOR_WORKER])
278 do
279 from workers.start
280 until workers.after
281 loop
282 live_parfor (workers.item)
283 workers.forth
284 end
285 end
286
287 live_parfor (worker: separate PARFOR_WORKER)
288 do
289 worker.live
290 end
291
292 workers_parfor_join (workers: LINKED_LIST [separate PARFOR_WORKER])
293 do
294 from workers.start
295 until workers.after
296 loop
297 join_parfor (workers.item)
298 workers.forth
299 end
300 end
301
302 end -- class MAIN

Properties

Name Value
svn:eol-style native
svn:keywords author date id revision

  ViewVC Help
Powered by ViewVC 1.1.23