annotate example/regex_mas/main.cc @ 1746:f2f69b73afe9 draft

remove global variable in regex_mas
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Mon, 18 Nov 2013 18:15:04 +0900
parents ef246e421c8c
children efbb42f8077a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <string.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <sys/mman.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <sys/types.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include <sys/stat.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include <fcntl.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include <unistd.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #include <sys/time.h>
1690
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1682
diff changeset
10 #include <iostream>
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1682
diff changeset
11 #include <vector>
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include "TaskManager.h"
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #include "SchedTask.h"
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include "Func.h"
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #include "WordCount.h"
1680
e44e5a18392c fix regex_mas.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1676
diff changeset
16 #define EXTRA_LENGTH 4 //多く取ってくる文字数(search word length - 1)
1630
d2581892b8ad fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
17
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 /* ;TODO
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 * PS3でCPU数が2以上の時に、あまりが計算されてない
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 extern void task_init();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 void TMend(TaskManager *);
1645
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
24 static double st_time;
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
25 static double ed_time;
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 int all = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 int use_task_array = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 int use_task_creater = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 int use_compat = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 int array_task_num = 8;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 int spe_num = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 CPU_TYPE spe_cpu = SPE_ANY;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-file filename]\n";
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
1645
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
35 static double
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
36 getTime() {
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
37 struct timeval tv;
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
38 gettimeofday(&tv, NULL);
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
39 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
40 }
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 typedef struct {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 caddr_t file_mmap;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 off_t size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 } st_mmap_t;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 static int
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 fix_byte(int size,int fix_byte_size)
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 return size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 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
58 my_read(TaskManager *manager,char *filename)
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 /*マッピングだよ!*/
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 int fd = -1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 st_mmap_t st_mmap;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 struct stat sb;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 if ((fd=open(filename,O_RDONLY,0666))==0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 fprintf(stderr,"can't open %s\n",filename);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 if (fstat(fd,&sb)) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 fprintf(stderr,"can't fstat %s\n",filename);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 /*sizeをページングサイズの倍数にあわせる*/
1647
0dcdaa4dfecb fix bugs regex/mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1645
diff changeset
74 st_mmap.size = fix_byte(sb.st_size,4096);
1707
64bb17ddc3e6 change "fread" to "read" in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1692
diff changeset
75 st_mmap.file_mmap = (char*)manager->allocate(st_mmap.size);
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
1707
64bb17ddc3e6 change "fread" to "read" in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1692
diff changeset
77 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
78
6b3991ac3f07 changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1690
diff changeset
79 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
80 fprintf(stderr,"Can't mmap file\n");
6b3991ac3f07 changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1690
diff changeset
81 perror(NULL);
6b3991ac3f07 changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1690
diff changeset
82 exit(0);
6b3991ac3f07 changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1690
diff changeset
83 }
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 return st_mmap;
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 }
6b3991ac3f07 changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1690
diff changeset
88
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 static void
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size)
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 if (task_count < array_task_num) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 array_task_num = task_count;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 if (task_count<=0) return;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 if (use_task_array) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 int spl = spe_num * array_task_num;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 int loop = (task_count + spl - 1) / spl;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 for (int i = 0; i < loop; i += 1) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
1676
342c36d5582e fix bug
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1664
diff changeset
105 if (w->task_num < spe_num) spe_num = w->task_num;
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 // ここから
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 Task **t_exec = (Task**)manager->allocate(sizeof(Task*)*spe_num);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
1690
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1682
diff changeset
111 for (int k = 0; k < spe_num; k++) {
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 task_array[k] = manager->create_task_array(TASK_EXEC,array_task_num,1,1,1);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 t_exec[k] = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 if (all) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 w->t_print->wait_for(task_array[k]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 t_next->wait_for(task_array[k]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 for (int j = 0; j < array_task_num; j++) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 for (int k = 0; k < spe_num; k++) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 int a = w->task_spwaned++;
1740
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1723
diff changeset
125
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 if (w->size < size) size = w->size;
1740
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1723
diff changeset
127
1680
e44e5a18392c fix regex_mas.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1676
diff changeset
128 int set_one_task_length = size/sizeof(char);
1740
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1723
diff changeset
129 //const int ONE_TASK_LENGTH = w->division_size;
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1723
diff changeset
130 //const int ONE_LOOP_LENGTH = array_task_num*spe_num*ONE_TASK_LENGTH;
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1723
diff changeset
131 //const int ARRAY_LENGTH_SIZE = spe_num * ONE_TASK_LENGTH;
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1723
diff changeset
132 //int offset = ONE_LOOP_LENGTH * i + ARRAY_LENGTH_SIZE*j + ONE_TASK_LENGTH*k;
1680
e44e5a18392c fix regex_mas.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1676
diff changeset
133 t_exec[k] = task_array[k]->next_task_array(TASK_EXEC,t_exec[k]);
e44e5a18392c fix regex_mas.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1676
diff changeset
134
e44e5a18392c fix regex_mas.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1676
diff changeset
135 if(size != w->size){ //最後のタスクかどうかの判定
1743
36eb8c21281a remove warning in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1740
diff changeset
136 t_exec[k]->set_param(0,&set_one_task_length + EXTRA_LENGTH);
1662
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
137 t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, size+EXTRA_LENGTH);
1744
68e5872085ff set_inData(rbuf,1) bugs? same address get_input Data in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1743
diff changeset
138 t_exec[k]->set_inData(1,w->search_word, w->search_word_len);
1647
0dcdaa4dfecb fix bugs regex/mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1645
diff changeset
139 }else{
1743
36eb8c21281a remove warning in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1740
diff changeset
140 t_exec[k]->set_param(0,&set_one_task_length);
1662
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
141 t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, size);
1744
68e5872085ff set_inData(rbuf,1) bugs? same address get_input Data in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1743
diff changeset
142 t_exec[k]->set_inData(1,w->search_word, w->search_word_len);
1647
0dcdaa4dfecb fix bugs regex/mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1645
diff changeset
143 }
1740
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1723
diff changeset
144
1662
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
145 t_exec[k]->set_outData(0,w->o_data + a*w->out_size, w->division_out_size);
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
146
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 w->size -= size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 w->task_num--;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 for (int k = 0; k < spe_num; k++) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 task_array[k]->spawn_task_array(t_exec[k]->next());
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 task_array[k]->set_cpu(spe_cpu);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 task_array[k]->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 return;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 for (int i = 0; i < task_count; i += array_task_num) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 HTask *h_exec = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 for (int j = 0; j < array_task_num; j++) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 int i = w->task_spwaned++;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 if (w->size < size) size = w->size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 int length = size/sizeof(char);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 if (size==0) break;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 if (use_compat) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 h_exec = manager->create_task(TASK_EXEC);
1743
36eb8c21281a remove warning in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1740
diff changeset
174 h_exec->set_param(0,&length);
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 if (all) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 w->t_print->wait_for(h_exec);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 t_next->wait_for(h_exec);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 h_exec->set_cpu(spe_cpu);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 h_exec->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 h_exec = manager->create_task(TASK_EXEC,
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 (memaddr)(w->file_mmap + i*w->division_size), size,
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 (memaddr)(w->o_data + i*w->out_size), w->division_out_size);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 if (all) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 w->t_print->wait_for(h_exec);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 t_next->wait_for(h_exec);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 h_exec->set_cpu(spe_cpu);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 h_exec->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 w->size -= size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 w->task_num--;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 /**
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 * このTaskは、PPE上で実行されるので、並列に実行されることはない
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 * 二つ実行されていて、Task が足りなくなることがないようにしている。
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 SchedDefineTask1(RUN_TASK_BLOCKS,run16);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 static int
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 run16(SchedTask *manager, void *in, void *out)
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 WordCount *w = *(WordCount **)in;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 if (w->task_num < w->task_blocks) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 // last case
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 while (w->size >= w->division_size)
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 run_tasks(manager,w,w->task_num, w->t_print, w->division_size);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 // remaining data
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 while (w->size>0)
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 run_tasks(manager,w,1, w->t_print, w->size);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 // printf("run16 last %d\n",w->task_num);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS,
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 (memaddr)&w->self,sizeof(memaddr),0,0);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 w->t_print->wait_for(t_next);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 run_tasks(manager,w, w->task_blocks, t_next, w->division_size);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 t_next->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 // printf("run16 next %d\n",w->task_num);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 return 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 static int blocks = 48;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 //static int blocks = 31 * 6 * 24;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 static int division = 16; // in Kbyte
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 static void
1746
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
249 run_start(TaskManager *manager, char *filename,unsigned char *search_word)
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 HTaskPtr t_print;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 st_mmap_t st_mmap;
1691
6b3991ac3f07 changed mmap to fread.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1690
diff changeset
254 //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
255 st_mmap = my_read(manager,filename);
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount));
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 // bzero(w,sizeof(WordCount));
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
1745
ef246e421c8c refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1744
diff changeset
259 /* prepare BMSearch*/
ef246e421c8c refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1744
diff changeset
260 w->search_word = search_word;
ef246e421c8c refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1744
diff changeset
261 w->search_word_len = strlen((const char*)w->search_word);
ef246e421c8c refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1744
diff changeset
262
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 //w->task_blocks = blocks;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 w->self = w;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 w->task_spwaned = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 /*sizeはdivision_sizeの倍数にしている。*/
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 w->size = w->file_size = st_mmap.size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 w->file_mmap = st_mmap.file_mmap;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 /* 1task分のデータサイズ(byte) */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 if (w->size >= 1024*division) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 w->division_size = 1024 * division;/*16kbyte*/
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 w->division_size = w->size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276
1680
e44e5a18392c fix regex_mas.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1676
diff changeset
277 /* exec output only "match_num" */
e44e5a18392c fix regex_mas.
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1676
diff changeset
278 w->status_num = 1;
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 /* taskの数 */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 w->task_num = w->size / w->division_size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 w->task_num = w->task_num + (w->division_size*w->task_num < w->size);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 int out_task_num = w->task_num;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 if(!all) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 w->task_blocks = blocks;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 w->task_blocks = w->task_num;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 w->out_task_num = out_task_num;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(4byte)を使用 */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293
1660
8b50b1ee068e change result position to match_num.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1655
diff changeset
294 w->division_out_size = sizeof(unsigned long long)*1;
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 int out_size = w->division_out_size*out_task_num;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 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
297 w->out_size = 1;
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 /*各SPEの結果を合計して出力するタスク*/
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 t_print = manager->create_task(TASK_PRINT,
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 (memaddr)&w->self,sizeof(memaddr),0,0);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 w->t_print = t_print;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
1690
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1682
diff changeset
305 for(int i = 0;i<2;i++) {
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 /* Task を task_blocks ずつ起動する Task */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 /* serialize されていると仮定する... */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS,
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 (memaddr)&w->self,sizeof(memaddr),0,0);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 t_print->wait_for(t_exec);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 t_exec->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 t_print->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 static char*
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 init(int argc, char **argv)
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 char *filename = 0;
1746
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
322 unsigned char *search_word = 0;
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 for (int i = 1; argv[i]; ++i) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 if (strcmp(argv[i], "-file") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 filename = argv[i+1];
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 } else if (strcmp(argv[i], "-division") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 division = atoi(argv[i+1]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 } else if (strcmp(argv[i], "-block") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 blocks = atoi(argv[i+1]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 } else if (strcmp(argv[i], "-a") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 // create task all at once
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 all = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 } else if (strcmp(argv[i], "-c") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 use_task_array = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 use_compat = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 } else if (strcmp(argv[i], "-s") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 use_task_array = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 use_compat = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 } else if (strcmp(argv[i], "-t") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 use_task_creater = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 use_task_array = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 use_compat = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 } else if (strcmp(argv[i], "-anum") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 array_task_num = atoi(argv[i+1]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 } else if (strcmp(argv[i], "-g") == 0 ) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 spe_cpu = GPU_0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 } else if (strcmp(argv[i], "-cpu") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 spe_num = atoi(argv[i+1]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 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
351 } else if (strcmp(argv[i], "-sw") == 0) {
1651
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1650
diff changeset
352 search_word = (unsigned char*)argv[i+1];
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 if (filename==0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 puts(usr_help_str);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 exit(1);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 return filename;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 int
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 TMmain(TaskManager *manager, int argc, char *argv[])
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 char *filename = 0;
1746
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
369 unsigned char *search_word = 0;
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 filename = init(argc, argv);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371
1746
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
372 for (int i = 1; argv[i]; ++i) {
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
373 if (strcmp(argv[i], "-sw") == 0) {
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
374 search_word = (unsigned char*)argv[i+1];
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
375 }
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
376 }
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
377
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 if (filename < 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 return -1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381
1746
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
382 if (search_word < 0) {
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
383 return -1;
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
384 }
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
385
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 task_init();
1723
d54e287eeef3 change time measurement point in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1707
diff changeset
387 st_time = getTime();
1746
f2f69b73afe9 remove global variable in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1745
diff changeset
388 run_start(manager, filename,search_word);
1645
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
389 manager->set_TMend(TMend);
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 return 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392
1645
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
393 void
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
394 TMend(TaskManager *manager)
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
395 {
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
396 ed_time = getTime();
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
397 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
398 }
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1642
diff changeset
399
1662
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
400 /* end */