Mercurial > hg > Game > Cerium
annotate example/regex_mas/main.cc @ 1813:d7973604e81f draft
fix memin size
author | kkb |
---|---|
date | Thu, 12 Dec 2013 18:34:16 +0900 |
parents | a77876642bb3 |
children | 69250f6636e0 |
rev | line source |
---|---|
1598 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <sys/mman.h> | |
5 #include <sys/types.h> | |
6 #include <sys/stat.h> | |
7 #include <fcntl.h> | |
8 #include <unistd.h> | |
9 #include <sys/time.h> | |
1690 | 10 #include <iostream> |
11 #include <vector> | |
1598 | 12 #include "TaskManager.h" |
13 #include "SchedTask.h" | |
14 #include "Func.h" | |
15 #include "WordCount.h" | |
1630 | 16 |
1598 | 17 /* ;TODO |
18 * PS3でCPU数が2以上の時に、あまりが計算されてない | |
19 */ | |
20 | |
21 extern void task_init(); | |
22 void TMend(TaskManager *); | |
1645
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
23 static double st_time; |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
24 static double ed_time; |
1598 | 25 int all = 0; |
26 int use_task_array = 1; | |
27 int use_task_creater = 0; | |
28 int use_compat = 0; | |
29 int array_task_num = 8; | |
30 int spe_num = 1; | |
1748 | 31 |
1761
b98e23499add
refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1759
diff
changeset
|
32 unsigned char *sword = 0; |
1788 | 33 int task_count = 0; |
34 | |
1751 | 35 static int division = 16; // in Kbyte |
1748 | 36 //static unsigned char* search_word; |
1598 | 37 CPU_TYPE spe_cpu = SPE_ANY; |
1776
1c429035e0d1
Refactoring conditional expression
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1774
diff
changeset
|
38 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-sw search_word] [-file filename]\n Required filename & search_word\n"; |
1598 | 39 |
1645
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
40 static double |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
41 getTime() { |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
42 struct timeval tv; |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
43 gettimeofday(&tv, NULL); |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
44 return tv.tv_sec + (double)tv.tv_usec*1e-6; |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
45 } |
1598 | 46 |
47 typedef struct { | |
48 caddr_t file_mmap; | |
49 off_t size; | |
50 } st_mmap_t; | |
51 | |
52 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ | |
53 static int | |
54 fix_byte(int size,int fix_byte_size) | |
55 { | |
56 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; | |
57 | |
58 return size; | |
59 } | |
60 | |
61 | |
62 static st_mmap_t | |
1707
64bb17ddc3e6
change "fread" to "read" in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1692
diff
changeset
|
63 my_read(TaskManager *manager,char *filename) |
1598 | 64 { |
65 /*マッピングだよ!*/ | |
66 int fd = -1; | |
67 st_mmap_t st_mmap; | |
68 struct stat sb; | |
69 | |
70 if ((fd=open(filename,O_RDONLY,0666))==0) { | |
71 fprintf(stderr,"can't open %s\n",filename); | |
72 } | |
73 | |
74 if (fstat(fd,&sb)) { | |
75 fprintf(stderr,"can't fstat %s\n",filename); | |
76 } | |
77 | |
78 /*sizeをページングサイズの倍数にあわせる*/ | |
1789 | 79 //st_mmap.size = fix_byte(sb.st_size,4096); |
1751 | 80 st_mmap.size = fix_byte(sb.st_size,division * 1024); |
1707
64bb17ddc3e6
change "fread" to "read" in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1692
diff
changeset
|
81 st_mmap.file_mmap = (char*)manager->allocate(st_mmap.size); |
1598 | 82 |
1707
64bb17ddc3e6
change "fread" to "read" in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1692
diff
changeset
|
83 read(fd,st_mmap.file_mmap,st_mmap.size); |
1691
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
84 |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
85 if (st_mmap.file_mmap == (caddr_t)-1) { |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
86 fprintf(stderr,"Can't mmap file\n"); |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
87 perror(NULL); |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
88 exit(0); |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
89 } |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
90 |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
91 return st_mmap; |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
92 } |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
93 |
1598 | 94 static void |
95 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) | |
96 { | |
1788 | 97 |
1787
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
98 if (task_count < array_task_num) { |
1598 | 99 array_task_num = task_count; |
100 if (task_count<=0) return; | |
101 } | |
1789 | 102 for (int i = 0; i < task_count; i += array_task_num) { |
103 HTask *task_array; | |
104 if (use_task_array) { | |
105 int task_num = (w->size+size-1)/size; | |
106 if (task_num>array_task_num) task_num = array_task_num; | |
1806
a77876642bb3
change get_input() to get_inputAddr() in regex_mas/ppe/Exec.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1801
diff
changeset
|
107 task_array = manager->create_task_array(TASK_EXEC,task_num,1,3,1); |
1789 | 108 if (!all) { |
109 t_next->wait_for(task_array); | |
110 } else { | |
111 w->t_print->wait_for(task_array); | |
1787
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
112 } |
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
113 } |
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
114 |
1789 | 115 Task *t_exec = 0; |
1598 | 116 HTask *h_exec = 0; |
117 for (int j = 0; j < array_task_num; j++) { | |
1789 | 118 int a = w->task_spwaned++; |
1598 | 119 if (w->size < size) size = w->size; |
120 if (size==0) break; | |
1789 | 121 if (use_task_array) { |
122 t_exec = task_array->next_task_array(TASK_EXEC,t_exec); | |
123 t_exec->set_inData(0,w->file_mmap + a*w->division_size, size); | |
1795
0aefbf042eb3
setting Data method change set_param to set_inData
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1789
diff
changeset
|
124 t_exec->set_inData(1,w->search_word, w->search_word_len); |
0aefbf042eb3
setting Data method change set_param to set_inData
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1789
diff
changeset
|
125 t_exec->set_inData(2,w->BMskip_table, 256); |
1787
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
126 |
1789 | 127 t_exec->set_param(0,(long)a); |
128 | |
129 t_exec->set_outData(0,w->o_data + a*w->out_size, w->division_out_size); | |
130 } else if (use_compat) { | |
1787
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
131 h_exec = manager->create_task(TASK_EXEC); |
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
132 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size); |
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
133 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); |
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
134 |
1789 | 135 t_next->wait_for(h_exec); |
1598 | 136 |
137 h_exec->set_cpu(spe_cpu); | |
138 h_exec->spawn(); | |
139 } else { | |
140 h_exec = manager->create_task(TASK_EXEC, | |
141 (memaddr)(w->file_mmap + i*w->division_size), size, | |
142 (memaddr)(w->o_data + i*w->out_size), w->division_out_size); | |
1789 | 143 t_next->wait_for(h_exec); |
1598 | 144 h_exec->set_cpu(spe_cpu); |
145 h_exec->spawn(); | |
146 } | |
147 w->size -= size; | |
1801
e91bf033443a
fix task_size in run16
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1799
diff
changeset
|
148 w->task_num--; |
1598 | 149 } |
1789 | 150 if (use_task_array) { |
151 task_array->spawn_task_array(t_exec->next()); | |
152 task_array->set_cpu(spe_cpu); | |
153 task_array->spawn(); | |
154 } else { | |
155 //if (!all) t_next->wait_for(h_exec); | |
156 } | |
1598 | 157 } |
158 } | |
159 | |
160 /** | |
161 * このTaskは、PPE上で実行されるので、並列に実行されることはない | |
162 * 二つ実行されていて、Task が足りなくなることがないようにしている。 | |
163 */ | |
164 | |
165 SchedDefineTask1(RUN_TASK_BLOCKS,run16); | |
166 | |
167 static int | |
168 run16(SchedTask *manager, void *in, void *out) | |
169 { | |
170 WordCount *w = *(WordCount **)in; | |
171 | |
172 if (w->task_num < w->task_blocks) { | |
173 // last case | |
174 while (w->size >= w->division_size) | |
1789 | 175 run_tasks(manager,w,w->task_num, w->t_print, w->division_size + w->extra_len); |
1598 | 176 // remaining data |
177 while (w->size>0) | |
178 run_tasks(manager,w,1, w->t_print, w->size); | |
179 // printf("run16 last %d\n",w->task_num); | |
180 } else { | |
181 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, | |
182 (memaddr)&w->self,sizeof(memaddr),0,0); | |
183 w->t_print->wait_for(t_next); | |
184 | |
1801
e91bf033443a
fix task_size in run16
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1799
diff
changeset
|
185 run_tasks(manager,w, w->task_blocks, t_next, w->division_size + w->extra_len); |
1598 | 186 |
187 t_next->spawn(); | |
188 // printf("run16 next %d\n",w->task_num); | |
189 } | |
190 return 0; | |
191 } | |
192 | |
193 | |
194 static int blocks = 48; | |
195 //static int blocks = 31 * 6 * 24; | |
196 | |
1778 | 197 //Boyer Moore法に使用するテーブルを作成 |
1774
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
198 static int* |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
199 create_BMskiptable(unsigned char *search_word,int search_word_len,int *skip_table) |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
200 { |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
201 |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
202 for(int i = 0; i < 256; ++i){ |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
203 skip_table[i] = search_word_len; |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
204 } |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
205 |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
206 for(int j = 0; j < search_word_len - 1; ++j){ |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
207 skip_table[(int)search_word[j]] = search_word_len - j - 1; |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
208 } |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
209 return skip_table; |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
210 } |
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
211 |
1598 | 212 static void |
1795
0aefbf042eb3
setting Data method change set_param to set_inData
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1789
diff
changeset
|
213 run_start(TaskManager *manager, char *filename,unsigned char *search_word, int search_word_len) |
1598 | 214 { |
215 HTaskPtr t_print; | |
216 | |
217 st_mmap_t st_mmap; | |
1691
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
218 //st_mmap = my_mmap(filename); |
1707
64bb17ddc3e6
change "fread" to "read" in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1692
diff
changeset
|
219 st_mmap = my_read(manager,filename); |
1598 | 220 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); |
221 // bzero(w,sizeof(WordCount)); | |
222 | |
1745
ef246e421c8c
refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1744
diff
changeset
|
223 /* prepare BMSearch*/ |
1798
3babb36ac459
array(bmskip table) allocate size change 256 to 256*sizeof(int)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1797
diff
changeset
|
224 int *skip = (int*)manager->allocate(256 * sizeof(int)); |
1745
ef246e421c8c
refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1744
diff
changeset
|
225 w->search_word = search_word; |
1795
0aefbf042eb3
setting Data method change set_param to set_inData
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1789
diff
changeset
|
226 w->search_word_len = search_word_len; |
1774
39734c8cbcfe
To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1761
diff
changeset
|
227 w->BMskip_table = create_BMskiptable(w->search_word, w->search_word_len, skip); |
1777 | 228 w->extra_len = w->search_word_len - 1; |
1745
ef246e421c8c
refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1744
diff
changeset
|
229 |
1598 | 230 //w->task_blocks = blocks; |
231 w->self = w; | |
232 w->task_spwaned = 0; | |
233 | |
234 /*sizeはdivision_sizeの倍数にしている。*/ | |
235 w->size = w->file_size = st_mmap.size; | |
236 w->file_mmap = st_mmap.file_mmap; | |
237 /* 1task分のデータサイズ(byte) */ | |
238 if (w->size >= 1024*division) { | |
239 w->division_size = 1024 * division;/*16kbyte*/ | |
240 } else { | |
241 w->division_size = w->size; | |
242 } | |
243 | |
1680
e44e5a18392c
fix regex_mas.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1676
diff
changeset
|
244 /* exec output only "match_num" */ |
e44e5a18392c
fix regex_mas.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1676
diff
changeset
|
245 w->status_num = 1; |
1598 | 246 /* taskの数 */ |
247 w->task_num = w->size / w->division_size; | |
1789 | 248 printf("task num: %d\n", w->task_num); |
1598 | 249 w->task_num = w->task_num + (w->division_size*w->task_num < w->size); |
250 int out_task_num = w->task_num; | |
251 | |
252 if(!all) { | |
253 w->task_blocks = blocks; | |
254 } else { | |
255 w->task_blocks = w->task_num; | |
256 } | |
257 | |
258 w->out_task_num = out_task_num; | |
259 | |
260 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(4byte)を使用 */ | |
261 | |
1799
d9122ca02431
Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1798
diff
changeset
|
262 w->division_out_size = sizeof(unsigned long long)*2; |
1598 | 263 int out_size = w->division_out_size*out_task_num; |
264 w->o_data = (unsigned long long *)manager->allocate(out_size); | |
1660
8b50b1ee068e
change result position to match_num.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1655
diff
changeset
|
265 w->out_size = 1; |
1598 | 266 |
267 /*各SPEの結果を合計して出力するタスク*/ | |
268 | |
269 t_print = manager->create_task(TASK_PRINT, | |
270 (memaddr)&w->self,sizeof(memaddr),0,0); | |
271 w->t_print = t_print; | |
272 | |
1801
e91bf033443a
fix task_size in run16
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1799
diff
changeset
|
273 // for(int i = 0;i<2;i++) { |
1598 | 274 /* Task を task_blocks ずつ起動する Task */ |
275 /* serialize されていると仮定する... */ | |
276 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, | |
277 (memaddr)&w->self,sizeof(memaddr),0,0); | |
278 t_print->wait_for(t_exec); | |
1799
d9122ca02431
Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1798
diff
changeset
|
279 t_exec->iterate(2); |
1801
e91bf033443a
fix task_size in run16
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1799
diff
changeset
|
280 // t_exec->spawn(); |
e91bf033443a
fix task_size in run16
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1799
diff
changeset
|
281 // } |
1598 | 282 |
283 t_print->spawn(); | |
284 } | |
285 | |
286 static char* | |
287 init(int argc, char **argv) | |
288 { | |
289 | |
290 char *filename = 0; | |
291 | |
292 for (int i = 1; argv[i]; ++i) { | |
293 if (strcmp(argv[i], "-file") == 0) { | |
294 filename = argv[i+1]; | |
295 } else if (strcmp(argv[i], "-division") == 0) { | |
296 division = atoi(argv[i+1]); | |
297 } else if (strcmp(argv[i], "-block") == 0) { | |
298 blocks = atoi(argv[i+1]); | |
299 } else if (strcmp(argv[i], "-a") == 0) { | |
300 // create task all at once | |
301 all = 1; | |
302 } else if (strcmp(argv[i], "-c") == 0) { | |
303 use_task_array = 0; | |
304 use_compat = 1; | |
305 } else if (strcmp(argv[i], "-s") == 0) { | |
306 use_task_array = 0; | |
307 use_compat = 0; | |
308 } else if (strcmp(argv[i], "-t") == 0) { | |
309 use_task_creater = 1; | |
310 use_task_array = 0; | |
311 use_compat = 0; | |
312 } else if (strcmp(argv[i], "-anum") == 0) { | |
313 array_task_num = atoi(argv[i+1]); | |
314 } else if (strcmp(argv[i], "-g") == 0 ) { | |
315 spe_cpu = GPU_0; | |
316 } else if (strcmp(argv[i], "-cpu") == 0) { | |
317 spe_num = atoi(argv[i+1]); | |
318 if (spe_num==0) spe_num = 1; | |
1645
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
319 } else if (strcmp(argv[i], "-sw") == 0) { |
1761
b98e23499add
refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1759
diff
changeset
|
320 sword = (unsigned char*)argv[i+1]; |
1598 | 321 } |
322 } | |
1776
1c429035e0d1
Refactoring conditional expression
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1774
diff
changeset
|
323 if ((filename==0) || (sword==0)) { |
1598 | 324 puts(usr_help_str); |
325 exit(1); | |
326 } | |
327 | |
328 return filename; | |
329 } | |
330 | |
331 | |
332 int | |
333 TMmain(TaskManager *manager, int argc, char *argv[]) | |
334 { | |
335 | |
1785 | 336 char *filename = init(argc, argv); |
1796
355304646b4b
send array to task
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1795
diff
changeset
|
337 int sw_len = strlen((const char *)sword); |
1598 | 338 |
1795
0aefbf042eb3
setting Data method change set_param to set_inData
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1789
diff
changeset
|
339 unsigned char *search_word = (unsigned char*)manager->allocate(sw_len + 1); |
1797 | 340 memcpy(search_word, sword, sw_len + 1); |
1748 | 341 |
1598 | 342 task_init(); |
1723
d54e287eeef3
change time measurement point in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1707
diff
changeset
|
343 st_time = getTime(); |
1795
0aefbf042eb3
setting Data method change set_param to set_inData
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1789
diff
changeset
|
344 run_start(manager, filename, search_word, sw_len); |
1645
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
345 manager->set_TMend(TMend); |
1598 | 346 return 0; |
347 } | |
348 | |
1645
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
349 void |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
350 TMend(TaskManager *manager) |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
351 { |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
352 ed_time = getTime(); |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
353 printf("Time: %0.6f\n",ed_time-st_time); |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
354 } |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
355 |
1662 | 356 /* end */ |