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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 -- product: matrix-vector product
2 --
3 -- input:
4 -- matrix: a real matrix
5 -- vector: a real vector
6 -- nelts: the number of elements
7 --
8 -- output:
9 -- res: a real vector, whose values are the result of the product
10
11 class MAIN
12
13 inherit
14 ARGUMENTS
15
16 create
17 make
18
19 feature
20 make
21 local
22 nelts: INTEGER
23 i: INTEGER
24 res: ARRAY[REAL_64]
25 do
26 create in.make_open_read(separate_character_option_value('i'))
27 is_bench := index_of_word_option ("bench") > 0
28 in.read_integer
29 nelts := in.last_integer
30
31 create matrix.make_filled (0, nelts, nelts)
32 create vector.make_filled (0, 1, nelts)
33 create result_vector.make_filled (0, 1, nelts)
34
35 if not is_bench then
36 read_matrix (nelts, matrix)
37 read_vector (nelts, vector)
38 end
39
40 res := product(nelts)
41
42 if not is_bench then
43 print(nelts.out + "%N")
44 from i := 1
45 until i > nelts
46 loop
47 print (res [i].out + " ")
48 i := i + 1
49 end
50 print("%N")
51 end
52 end
53
54 read_vector (nelts: INTEGER; a_vector: separate ARRAY[REAL_64])
55 local
56 i: INTEGER
57 do
58 from i := 1
59 until i > nelts
60 loop
61 a_vector [i] := read_double
62 i := i + 1
63 end
64 end
65
66 read_matrix (nelts: INTEGER; a_matrix: separate ARRAY2[REAL_64])
67 local
68 i,j: INTEGER
69 do
70 from i := 1
71 until i > nelts
72 loop
73 from j := 1
74 until j > nelts
75 loop
76 a_matrix [i, j] := read_double
77 j := j + 1
78 end
79 i := i + 1
80 end
81 end
82
83 read_double: REAL_64
84 do
85 in.read_double
86 Result := in.last_double
87 end
88
89 num_workers: INTEGER = 4
90
91 product (nelts: INTEGER): ARRAY[REAL_64]
92 local
93 worker: separate PARFOR_WORKER
94 workers: LINKED_LIST [separate PARFOR_WORKER]
95 start, height, i: INTEGER
96 do
97 create workers.make
98
99 from
100 start := 0
101 i := 0
102 until i >= num_workers
103 loop
104 height := (nelts - start) // (num_workers - i)
105
106 if height > 0 then
107 create worker.make
108 (start + 1
109 , start + height
110 , nelts
111 , matrix
112 , vector)
113
114 workers.extend(worker)
115 end
116
117 start := start + height
118 i := i + 1
119 end
120 -- parallel for on rows
121 print ("Living workers%N")
122 workers_live (workers)
123
124 -- join workers
125 print ("Joining workers%N")
126 workers_join (workers)
127
128 Result := to_local (nelts, result_vector)
129 end
130
131 -- to_separate(nelts: INTEGER; vector: ARRAY[REAL_64])
132 -- : separate ARRAY[REAL_64]
133 -- local
134 -- res: separate ARRAY[REAL_64]
135 -- do
136 -- create res.make_empty
137 -- across 1 |..| nelts as ic loop
138 -- res.force(vector.item(ic.item), ic.item);
139 -- end
140 -- Result := res
141 -- end
142
143 to_local(nelts: INTEGER; a_vector: separate ARRAY[REAL_64]): ARRAY[REAL_64]
144 local
145 i: INTEGER
146 do
147 create Result.make_filled (0, 1, nelts)
148 from i := 1
149 until i > nelts
150 loop
151 Result [i] := a_vector [i]
152 i := i + 1
153 end
154 end
155
156 feature {NONE}
157 workers_live (workers: LINKED_LIST [separate PARFOR_WORKER])
158 do
159 from workers.start
160 until workers.after
161 loop
162 worker_live (workers.item)
163 workers.forth
164 end
165 end
166
167 workers_join (workers: LINKED_LIST [separate PARFOR_WORKER])
168 do
169 from workers.start
170 until workers.after
171 loop
172 print ("Joining%N")
173 worker_join (workers.item)
174 workers.forth
175 end
176 end
177
178 worker_live (worker: separate PARFOR_WORKER)
179 do
180 worker.live
181 end
182
183 worker_join(worker: separate PARFOR_WORKER)
184 local
185 i: INTEGER
186 do
187 from
188 i := worker.start
189 until
190 i >= worker.final
191 loop
192 result_vector [i] := worker.get_res(i)
193 i := i + 1
194 end
195 end
196
197
198 feature {NONE}
199 in: PLAIN_TEXT_FILE
200 is_bench: BOOLEAN
201 matrix: separate ARRAY2[REAL_64]
202 vector: separate ARRAY[REAL_64]
203 result_vector: ARRAY[REAL_64]
204
205
206 end -- class MAIN
207

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23