Mercurial > hg > Game > Cerium
annotate example/regex_mas/main.cc @ 1950:1f297d3eacb1 draft
fix bugs
author | masa |
---|---|
date | Thu, 06 Feb 2014 17:55:06 +0900 |
parents | f3e9f811c387 |
children | 30b95f372a0d |
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; | |
1855
69250f6636e0
insert divide fileread in regex_mas (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1806
diff
changeset
|
29 int div_read = 0; |
1598 | 30 int array_task_num = 8; |
31 int spe_num = 1; | |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
32 int divide_read_flag = 0; |
1855
69250f6636e0
insert divide fileread in regex_mas (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1806
diff
changeset
|
33 int DIVISION_SIZE = 4*4096; |
1939
d862c573bf84
bugfix (change variable types in WordCount.h)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1937
diff
changeset
|
34 int READ_DIVISION_SIZE = 4*4096 * 1024; |
1748 | 35 |
1761
b98e23499add
refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1759
diff
changeset
|
36 unsigned char *sword = 0; |
1788 | 37 int task_count = 0; |
38 | |
1751 | 39 static int division = 16; // in Kbyte |
1598 | 40 CPU_TYPE spe_cpu = SPE_ANY; |
1937
e5b4e61b6f85
change allocate size int to long long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1934
diff
changeset
|
41 CPU_TYPE read_spe_cpu = IO_0; |
1916
68ee760e1c7e
running divide read
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1914
diff
changeset
|
42 |
1776
1c429035e0d1
Refactoring conditional expression
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1774
diff
changeset
|
43 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 | 44 |
1645
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
45 static double |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
46 getTime() { |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
47 struct timeval tv; |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
48 gettimeofday(&tv, NULL); |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
49 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
|
50 } |
1598 | 51 |
52 typedef struct { | |
53 caddr_t file_mmap; | |
54 off_t size; | |
55 } st_mmap_t; | |
56 | |
57 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ | |
1932
f57779f1d93a
change file size type int to long long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1916
diff
changeset
|
58 static unsigned long long |
f57779f1d93a
change file size type int to long long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1916
diff
changeset
|
59 fix_byte(unsigned long long size,int fix_byte_size) |
1598 | 60 { |
61 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; | |
62 | |
63 return size; | |
64 } | |
65 | |
1947
ef751840b388
running mmap mode (cannot running divide read)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1946
diff
changeset
|
66 |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
67 SchedDefineTask1(MMAP,my_mmap); |
1863
3f058fee44d2
fix read_run16 loops ( cannot running )
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1862
diff
changeset
|
68 |
3f058fee44d2
fix read_run16 loops ( cannot running )
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1862
diff
changeset
|
69 static int |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
70 my_mmap(SchedTask *s, void *in, void *out) |
1862
64c571a30bdb
change Cerium Task to function() divide read ( cannot running )
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1860
diff
changeset
|
71 { |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
72 WordCountPtr w = (WordCountPtr)in; |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
73 /*マッピングだよ!*/ |
1856
429cf7e669a1
some fix (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1855
diff
changeset
|
74 |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
75 int map = MAP_PRIVATE; |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
76 st_mmap_t st_mmap; |
1598 | 77 |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
78 int fd = w->fd; |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
79 st_mmap.size = fix_byte(w->read_filesize,4096); |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
80 w->file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); |
1691
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
81 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
|
82 fprintf(stderr,"Can't mmap file\n"); |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
83 |
1691
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
84 perror(NULL); |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
85 exit(0); |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
86 } |
6b3991ac3f07
changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1690
diff
changeset
|
87 |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
88 return 0; |
1691
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 |
1598 | 91 static void |
1945 | 92 run_tasks(SchedTask *manager, WordCount *w, int task_count,HTaskPtr t_read, HTaskPtr t_next, int size) |
1598 | 93 { |
1788 | 94 |
1787
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
95 if (task_count < array_task_num) { |
1598 | 96 array_task_num = task_count; |
97 if (task_count<=0) return; | |
98 } | |
1789 | 99 for (int i = 0; i < task_count; i += array_task_num) { |
100 HTask *task_array; | |
101 if (use_task_array) { | |
102 int task_num = (w->size+size-1)/size; | |
103 if (task_num>array_task_num) task_num = array_task_num; | |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
104 task_array = manager->create_task_array(TASK_EXEC,task_num,1,3,1); |
1947
ef751840b388
running mmap mode (cannot running divide read)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1946
diff
changeset
|
105 if (t_read != 0) task_array->wait_for(t_read); |
1789 | 106 if (!all) { |
107 t_next->wait_for(task_array); | |
108 } else { | |
109 w->t_print->wait_for(task_array); | |
1787
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
110 } |
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
111 } |
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
112 |
1789 | 113 Task *t_exec = 0; |
1598 | 114 HTask *h_exec = 0; |
115 for (int j = 0; j < array_task_num; j++) { | |
1946
502521591d7c
remove RUN_READ_BLOCKS (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1945
diff
changeset
|
116 long i = w->task_spawned++; |
1598 | 117 if (w->size < size) size = w->size; |
118 if (size==0) break; | |
1789 | 119 if (use_task_array) { |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
120 t_exec = task_array->next_task_array(TASK_EXEC,t_exec); |
1945 | 121 t_exec->set_inData(0,w->file_mmap + i*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
|
122 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
|
123 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
|
124 |
1945 | 125 t_exec->set_param(0,(long)i); |
1789 | 126 |
1946
502521591d7c
remove RUN_READ_BLOCKS (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1945
diff
changeset
|
127 t_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); |
1789 | 128 } else if (use_compat) { |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
129 h_exec = manager->create_task(TASK_EXEC); |
1947
ef751840b388
running mmap mode (cannot running divide read)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1946
diff
changeset
|
130 if (t_read != 0) h_exec->wait_for(t_read); |
1787
5cde37f02c66
back main.cc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1786
diff
changeset
|
131 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
|
132 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
|
133 |
1789 | 134 t_next->wait_for(h_exec); |
1598 | 135 |
136 h_exec->set_cpu(spe_cpu); | |
137 h_exec->spawn(); | |
138 } else { | |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
139 h_exec = manager->create_task(TASK_EXEC, |
1598 | 140 (memaddr)(w->file_mmap + i*w->division_size), size, |
141 (memaddr)(w->o_data + i*w->out_size), w->division_out_size); | |
1947
ef751840b388
running mmap mode (cannot running divide read)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1946
diff
changeset
|
142 if (t_read != 0) h_exec->wait_for(t_read); |
1789 | 143 t_next->wait_for(h_exec); |
1598 | 144 h_exec->set_cpu(spe_cpu); |
145 h_exec->spawn(); | |
146 } | |
1934
3d54a6c26caa
fix w->size calc
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1932
diff
changeset
|
147 w->size -= w->division_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 | |
1855
69250f6636e0
insert divide fileread in regex_mas (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1806
diff
changeset
|
165 SchedDefineTask1(RUN_TASK_BLOCKS,task_run16); |
1598 | 166 |
167 static int | |
1855
69250f6636e0
insert divide fileread in regex_mas (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1806
diff
changeset
|
168 task_run16(SchedTask *manager, void *in, void *out) |
1598 | 169 { |
170 WordCount *w = *(WordCount **)in; | |
171 | |
1949
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
172 HTaskPtr t_read = manager->create_task(READ_TASK); |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
173 w->t_print->wait_for(t_read); |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
174 t_read->set_cpu(read_spe_cpu); |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
175 t_read->set_param(0,w->fd); |
1948 | 176 |
1598 | 177 if (w->task_num < w->task_blocks) { |
1949
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
178 t_read->set_param(1,w->task_spawned*w->division_size); |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
179 t_read->set_outData(0, w->file_mmap + w->task_spawned * w->division_size, w->task_blocks * w->division_size); |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
180 |
1598 | 181 // last case |
182 while (w->size >= w->division_size) | |
1948 | 183 run_tasks(manager,w,w->task_num,t_read,w->t_print, w->division_size + w->extra_len); |
1598 | 184 // remaining data |
185 while (w->size>0) | |
1948 | 186 run_tasks(manager,w,1,t_read,w->t_print, w->size); |
1949
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
187 |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
188 t_read->set_param(2,w->task_spawned*w->division_size); |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
189 t_read->spawn(); |
1598 | 190 // printf("run16 last %d\n",w->task_num); |
191 } else { | |
192 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, | |
193 (memaddr)&w->self,sizeof(memaddr),0,0); | |
194 w->t_print->wait_for(t_next); | |
1949
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
195 |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
196 t_read->set_param(1,w->task_spawned*w->division_size); |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
197 t_read->set_outData(0, w->file_mmap + w->task_spawned * w->division_size, w->task_blocks * w->division_size); |
1598 | 198 |
1949
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
199 run_tasks(manager,w, w->task_blocks, t_read, t_next, w->division_size + w->extra_len); |
1598 | 200 |
1949
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
201 t_read->set_param(2,w->task_spawned*w->division_size); |
1945 | 202 |
1948 | 203 t_read->spawn(); |
1598 | 204 t_next->spawn(); |
205 // printf("run16 next %d\n",w->task_num); | |
206 } | |
207 return 0; | |
208 } | |
209 | |
210 | |
211 static int blocks = 48; | |
212 //static int blocks = 31 * 6 * 24; | |
213 | |
1778 | 214 //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
|
215 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
|
216 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
|
217 { |
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
|
218 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
|
219 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
|
220 } |
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
|
221 |
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
|
222 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
|
223 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
|
224 } |
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
|
225 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
|
226 } |
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 |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
228 |
1598 | 229 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
|
230 run_start(TaskManager *manager, char *filename,unsigned char *search_word, int search_word_len) |
1598 | 231 { |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
232 long fd = (long)manager->allocate(sizeof(long)); |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
233 struct stat *sb = (struct stat*)manager->allocate(sizeof(struct stat)); |
1916
68ee760e1c7e
running divide read
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1914
diff
changeset
|
234 HTaskPtr t_exec; |
1860
d250caefe0ff
Register divide read as Cerium task
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1859
diff
changeset
|
235 |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
236 if ((fd=open(filename,O_RDONLY,0666))==0) { |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
237 fprintf(stderr,"can't open %s\n",filename); |
1945 | 238 return ; |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
239 } |
1860
d250caefe0ff
Register divide read as Cerium task
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1859
diff
changeset
|
240 |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
241 if (fstat(fd,sb)) { |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
242 fprintf(stderr,"can't fstat %s\n",filename); |
1945 | 243 return ; |
1855
69250f6636e0
insert divide fileread in regex_mas (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1806
diff
changeset
|
244 } |
69250f6636e0
insert divide fileread in regex_mas (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1806
diff
changeset
|
245 |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
246 WordCountPtr w = (WordCountPtr)manager->allocate(sizeof(WordCount)); |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
247 |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
248 w->self = w; |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
249 w->fd = fd; |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
250 w->read_filesize = sb->st_size; |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
251 |
1945 | 252 HTaskPtr r_read = NULL; |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
253 |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
254 if (divide_read_flag != 0) { |
1916
68ee760e1c7e
running divide read
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1914
diff
changeset
|
255 printf("[divide read mode]\n"); |
1950 | 256 w->file_mmap = (char*)manager->allocate(w->read_filesize); |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
257 }else { |
1916
68ee760e1c7e
running divide read
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1914
diff
changeset
|
258 printf("[mmap mode]\n"); |
1945 | 259 r_read = manager->create_task(MMAP , (memaddr)&w->self, sizeof(memaddr),0,0); |
1946
502521591d7c
remove RUN_READ_BLOCKS (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1945
diff
changeset
|
260 r_read->spawn(); |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
261 } |
1598 | 262 |
1916
68ee760e1c7e
running divide read
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1914
diff
changeset
|
263 |
1745
ef246e421c8c
refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1744
diff
changeset
|
264 /* prepare BMSearch*/ |
1949
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
265 int *skip = (int*)manager->allocate(256 * sizeof(int)); // 文字列に対応した table を用意 |
1745
ef246e421c8c
refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1744
diff
changeset
|
266 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
|
267 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
|
268 w->BMskip_table = create_BMskiptable(w->search_word, w->search_word_len, skip); |
1777 | 269 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
|
270 |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
271 /* original */ |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
272 HTaskPtr t_print; |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
273 |
1598 | 274 //w->task_blocks = blocks; |
275 w->self = w; | |
1946
502521591d7c
remove RUN_READ_BLOCKS (cannot running)
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1945
diff
changeset
|
276 w->task_spawned = 0; |
1598 | 277 |
278 /*sizeはdivision_sizeの倍数にしている。*/ | |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
279 w->size = w->file_size = w->read_filesize; |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
280 //w->file_mmap = st_mmap.file_mmap; |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
281 printf("w %lx\n",(long)w); |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
282 |
1598 | 283 /* 1task分のデータサイズ(byte) */ |
284 if (w->size >= 1024*division) { | |
285 w->division_size = 1024 * division;/*16kbyte*/ | |
286 } else { | |
287 w->division_size = w->size; | |
288 } | |
289 | |
1949
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
290 printf("division_size %ld\n",w->division_size); |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
291 |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
292 /* "word num" and "line num" */ |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
293 w->status_num = 2; |
1598 | 294 /* taskの数 */ |
295 w->task_num = w->size / w->division_size; | |
296 w->task_num = w->task_num + (w->division_size*w->task_num < w->size); | |
297 int out_task_num = w->task_num; | |
298 | |
299 if(!all) { | |
300 w->task_blocks = blocks; | |
301 } else { | |
302 w->task_blocks = w->task_num; | |
303 } | |
304 | |
305 w->out_task_num = out_task_num; | |
1949
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
306 printf("task_num %ld\n",w->task_num); |
f3e9f811c387
change some variables types int to long
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1948
diff
changeset
|
307 printf("out_task_num %ld\n",w->out_task_num); |
1598 | 308 |
309 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(4byte)を使用 */ | |
310 | |
1916
68ee760e1c7e
running divide read
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1914
diff
changeset
|
311 w->division_out_size = sizeof(unsigned long long)*1; |
1598 | 312 int out_size = w->division_out_size*out_task_num; |
313 w->o_data = (unsigned long long *)manager->allocate(out_size); | |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
314 w->out_size_ = out_size; |
1916
68ee760e1c7e
running divide read
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1914
diff
changeset
|
315 w->out_size = 1; |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
316 printf("out size %d\n",out_size); |
1598 | 317 |
318 /*各SPEの結果を合計して出力するタスク*/ | |
319 | |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
320 t_print = manager->create_task(PRINT_TASK, |
1598 | 321 (memaddr)&w->self,sizeof(memaddr),0,0); |
322 w->t_print = t_print; | |
323 | |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
324 for(int i=0;i<1;i++) { |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
325 /* Task を task_blocks ずつ起動する Task */ |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
326 /* serialize されていると仮定する... */ |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
327 t_exec = manager->create_task(RUN_TASK_BLOCKS, |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
328 (memaddr)&w->self,sizeof(memaddr),0,0); |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
329 t_print->wait_for(t_exec); |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
330 // t_exec->iterate(4); |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
331 t_exec->spawn(); |
1862
64c571a30bdb
change Cerium Task to function() divide read ( cannot running )
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1860
diff
changeset
|
332 } |
1916
68ee760e1c7e
running divide read
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1914
diff
changeset
|
333 w->t_exec = t_exec; |
68ee760e1c7e
running divide read
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1914
diff
changeset
|
334 |
1598 | 335 t_print->spawn(); |
336 } | |
337 | |
338 static char* | |
339 init(int argc, char **argv) | |
340 { | |
341 | |
342 char *filename = 0; | |
343 | |
344 for (int i = 1; argv[i]; ++i) { | |
345 if (strcmp(argv[i], "-file") == 0) { | |
346 filename = argv[i+1]; | |
347 } else if (strcmp(argv[i], "-division") == 0) { | |
348 division = atoi(argv[i+1]); | |
349 } else if (strcmp(argv[i], "-block") == 0) { | |
350 blocks = atoi(argv[i+1]); | |
351 } else if (strcmp(argv[i], "-a") == 0) { | |
352 // create task all at once | |
353 all = 1; | |
354 } else if (strcmp(argv[i], "-c") == 0) { | |
355 use_task_array = 0; | |
356 use_compat = 1; | |
357 } else if (strcmp(argv[i], "-s") == 0) { | |
358 use_task_array = 0; | |
359 use_compat = 0; | |
360 } else if (strcmp(argv[i], "-t") == 0) { | |
361 use_task_creater = 1; | |
362 use_task_array = 0; | |
363 use_compat = 0; | |
364 } else if (strcmp(argv[i], "-anum") == 0) { | |
365 array_task_num = atoi(argv[i+1]); | |
366 } else if (strcmp(argv[i], "-g") == 0 ) { | |
367 spe_cpu = GPU_0; | |
368 } else if (strcmp(argv[i], "-cpu") == 0) { | |
369 spe_num = atoi(argv[i+1]); | |
370 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
|
371 } 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
|
372 sword = (unsigned char*)argv[i+1]; |
1914
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
373 } else if (strcmp(argv[i], "-dr") == 0) { |
08e9e416c2e0
Implement divide read in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1863
diff
changeset
|
374 divide_read_flag = 1; |
1598 | 375 } |
376 } | |
1776
1c429035e0d1
Refactoring conditional expression
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1774
diff
changeset
|
377 if ((filename==0) || (sword==0)) { |
1598 | 378 puts(usr_help_str); |
379 exit(1); | |
380 } | |
381 | |
382 return filename; | |
383 } | |
384 | |
385 | |
386 int | |
387 TMmain(TaskManager *manager, int argc, char *argv[]) | |
388 { | |
389 | |
1785 | 390 char *filename = init(argc, argv); |
1796
355304646b4b
send array to task
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1795
diff
changeset
|
391 int sw_len = strlen((const char *)sword); |
1598 | 392 |
1795
0aefbf042eb3
setting Data method change set_param to set_inData
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1789
diff
changeset
|
393 unsigned char *search_word = (unsigned char*)manager->allocate(sw_len + 1); |
1797 | 394 memcpy(search_word, sword, sw_len + 1); |
1748 | 395 |
1598 | 396 task_init(); |
1723
d54e287eeef3
change time measurement point in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
1707
diff
changeset
|
397 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
|
398 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
|
399 manager->set_TMend(TMend); |
1598 | 400 return 0; |
401 } | |
402 | |
1645
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
403 void |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
404 TMend(TaskManager *manager) |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
405 { |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
406 ed_time = getTime(); |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
407 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
|
408 } |
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1642
diff
changeset
|
409 |
1662 | 410 /* end */ |