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
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"
1630
d2581892b8ad fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
16
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 /* ;TODO
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 * PS3でCPU数が2以上の時に、あまりが計算されてない
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 */
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 extern void task_init();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 int all = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 int use_task_array = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 int use_task_creater = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
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;
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
61370f2987ff minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1747
diff changeset
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
06f5a4b09396 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1787
diff changeset
37 int task_count = 0;
06f5a4b09396 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1787
diff changeset
38
1751
224802aba3bd minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1750
diff changeset
39 static int division = 16; // in Kbyte
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 typedef struct {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 caddr_t file_mmap;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 off_t size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 } st_mmap_t;
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 /*与えられた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
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 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
62
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 return size;
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
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 static void
1945
653c1caf1362 fix read spawn
masa
parents: 1940
diff changeset
92 run_tasks(SchedTask *manager, WordCount *w, int task_count,HTaskPtr t_read, HTaskPtr t_next, int size)
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 {
1788
06f5a4b09396 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1787
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 array_task_num = task_count;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 if (task_count<=0) return;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 }
1789
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
99 for (int i = 0; i < task_count; i += array_task_num) {
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
100 HTask *task_array;
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
101 if (use_task_array) {
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
102 int task_num = (w->size+size-1)/size;
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
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
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
106 if (!all) {
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
107 t_next->wait_for(task_array);
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
108 } else {
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
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
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
113 Task *t_exec = 0;
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 HTask *h_exec = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 if (w->size < size) size = w->size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 if (size==0) break;
1789
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
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
653c1caf1362 fix read spawn
masa
parents: 1940
diff changeset
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
653c1caf1362 fix read spawn
masa
parents: 1940
diff changeset
125 t_exec->set_param(0,(long)i);
1789
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
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
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
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
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
134 t_next->wait_for(h_exec);
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 h_exec->set_cpu(spe_cpu);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 h_exec->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 (memaddr)(w->file_mmap + i*w->division_size), size,
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
143 t_next->wait_for(h_exec);
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 h_exec->set_cpu(spe_cpu);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 h_exec->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 }
1789
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
150 if (use_task_array) {
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
151 task_array->spawn_task_array(t_exec->next());
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
152 task_array->set_cpu(spe_cpu);
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
153 task_array->spawn();
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
154 } else {
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
155 //if (!all) t_next->wait_for(h_exec);
82f8250f23d5 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1788
diff changeset
156 }
1598
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
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 * このTaskは、PPE上で実行されるので、並列に実行されることはない
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 * 二つ実行されていて、Task が足りなくなることがないようにしている。
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 WordCount *w = *(WordCount **)in;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1947
diff changeset
176
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 // last case
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 while (w->size >= w->division_size)
1948
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1947
diff changeset
183 run_tasks(manager,w,w->task_num,t_read,w->t_print, w->division_size + w->extra_len);
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 // remaining data
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 while (w->size>0)
1948
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1947
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 // printf("run16 last %d\n",w->task_num);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS,
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 (memaddr)&w->self,sizeof(memaddr),0,0);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
653c1caf1362 fix read spawn
masa
parents: 1940
diff changeset
202
1948
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1947
diff changeset
203 t_read->spawn();
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 t_next->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 // printf("run16 next %d\n",w->task_num);
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 return 0;
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 static int blocks = 48;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 //static int blocks = 31 * 6 * 24;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213
1778
0e6ca13d2ed0 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1777
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
653c1caf1362 fix read spawn
masa
parents: 1940
diff changeset
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
653c1caf1362 fix read spawn
masa
parents: 1940
diff changeset
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
653c1caf1362 fix read spawn
masa
parents: 1940
diff changeset
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
1f297d3eacb1 fix bugs
masa
parents: 1949
diff changeset
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
653c1caf1362 fix read spawn
masa
parents: 1940
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
7b11aceb41c4 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1776
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 //w->task_blocks = blocks;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 /* 1task分のデータサイズ(byte) */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 if (w->size >= 1024*division) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 w->division_size = 1024 * division;/*16kbyte*/
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->division_size = w->size;
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
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 /* taskの数 */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 w->task_num = w->size / w->division_size;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 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
297 int out_task_num = w->task_num;
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 if(!all) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 w->task_blocks = blocks;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 } else {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 w->task_blocks = w->task_num;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(4byte)を使用 */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 int out_size = w->division_out_size*out_task_num;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 /*各SPEの結果を合計して出力するタスク*/
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 (memaddr)&w->self,sizeof(memaddr),0,0);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 w->t_print = t_print;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 t_print->spawn();
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 static char*
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 init(int argc, char **argv)
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 char *filename = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 for (int i = 1; argv[i]; ++i) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 if (strcmp(argv[i], "-file") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 filename = argv[i+1];
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 } else if (strcmp(argv[i], "-division") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 division = atoi(argv[i+1]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 } else if (strcmp(argv[i], "-block") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 blocks = atoi(argv[i+1]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 } else if (strcmp(argv[i], "-a") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 // create task all at once
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 all = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 } else if (strcmp(argv[i], "-c") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 use_task_array = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 use_compat = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 } else if (strcmp(argv[i], "-s") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 use_task_array = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 use_compat = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 } else if (strcmp(argv[i], "-t") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 use_task_creater = 1;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 use_task_array = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 use_compat = 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 } else if (strcmp(argv[i], "-anum") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 array_task_num = atoi(argv[i+1]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 } else if (strcmp(argv[i], "-g") == 0 ) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 spe_cpu = GPU_0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 } else if (strcmp(argv[i], "-cpu") == 0) {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 spe_num = atoi(argv[i+1]);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 puts(usr_help_str);
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 exit(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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 return filename;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 int
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 TMmain(TaskManager *manager, int argc, char *argv[])
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 {
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389
1785
ae8e90890961 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1784
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
964978cf41ae minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1796
diff changeset
394 memcpy(search_word, sword, sw_len + 1);
1748
61370f2987ff minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1747
diff changeset
395
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 return 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 }
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
410 /* end */