Mercurial > hg > Game > Cerium
annotate example/word_count/main.cc @ 1083:54cf940e124a draft
minor fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 18 Dec 2010 12:02:19 +0900 |
parents | e8ef7f5f22f6 |
children | 2a63ba2c9506 |
rev | line source |
---|---|
393 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <sys/mman.h> | |
5 #include <sys/types.h> | |
6 #include <sys/stat.h> | |
7 #include <fcntl.h> | |
8 #include <unistd.h> | |
9 #include "TaskManager.h" | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
10 #include "SchedTask.h" |
393 | 11 #include "Func.h" |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
12 #include "WordCount.h" |
393 | 13 |
400 | 14 extern void task_init(); |
393 | 15 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
16 int all = 0; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
17 int use_task_array = 1; |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
18 int use_task_creater = 0; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
19 int use_compat = 0; |
967
daab1b74b32d
add anum option in WordCount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
950
diff
changeset
|
20 int array_task_num = 8; |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
21 int spe_num = 1; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
22 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
23 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-file filename]\n"; |
393 | 24 |
25 typedef struct { | |
26 caddr_t file_mmap; | |
27 off_t size; | |
28 } st_mmap_t; | |
29 | |
30 | |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
31 static void simple_task_creater(int in_total_size, int out_total_size, |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
32 int command, int in_data_size, int out_data_size, |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
33 void *in_data, void *out_data, SchedTask *manager, |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
34 HTask *wait_i, HTask *wait_me) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
35 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
36 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
37 int in_task_size = 0; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
38 int out_task_size = 0; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
39 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
40 if (in_total_size != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
41 in_task_size = in_total_size / in_data_size; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
42 if (in_total_size != in_task_size * in_data_size) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
43 printf("mismatch of in_total_size and in_data_size\n"); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
44 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
45 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
46 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
47 if (out_total_size != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
48 out_task_size = out_total_size / out_data_size; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
49 if (out_total_size != out_task_size * out_data_size) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
50 printf("mismatch of out_total_size and out_data_size\n"); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
51 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
52 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
53 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
54 /*in, out の大きい方に合わせるのがいいかな? Taskの数は1Task分に使うデータの大きいほうを取るような仕様がいいかな*/ |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
55 int task_num = (in_task_size > out_task_size) ? in_task_size : out_task_size; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
56 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
57 if (task_num == 0) task_num = 1; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
58 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
59 /*spe分あればいいのかな?*/ |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
60 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
61 int array_num = spe_num; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
62 if (task_num < array_num) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
63 array_num = task_num; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
64 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
65 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
66 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
67 HTaskPtr *task_array = (HTask**)manager->allocate(sizeof(HTask*)*array_num); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
68 TaskPtr *t_exec = (Task**)manager->allocate(sizeof(Task*)*array_num); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
69 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
70 int array_length = task_num / array_num; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
71 int rest = task_num % array_num; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
72 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
73 int index = 0; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
74 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
75 for (int k = 0; k < array_num; k++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
76 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
77 task_array[k] = manager->create_task_array(command,array_length,0,1,1); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
78 t_exec[k] = 0; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
79 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
80 if (wait_me != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
81 wait_me->wait_for(task_array[k]); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
82 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
83 if (wait_i != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
84 task_array[k]->wait_for(wait_i); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
85 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
86 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
87 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
88 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
89 for (int j = 0; j < array_length; j++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
90 for (int k = 0; k < array_num; k++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
91 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
92 t_exec[k] = task_array[k]->next_task_array(command,t_exec[k]); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
93 t_exec[k]->set_inData(0,(char*)in_data + index*in_data_size, in_data_size); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
94 t_exec[k]->set_outData(0,(char*)out_data + index*out_data_size, out_data_size); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
95 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
96 index++; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
97 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
98 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
99 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
100 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
101 for (int k = 0; k < array_num; k++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
102 task_array[k]->spawn_task_array(t_exec[k]->next()); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
103 task_array[k]->set_cpu(SPE_ANY); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
104 task_array[k]->spawn(); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
105 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
106 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
107 for (int k = 0; k < rest; k++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
108 HTaskPtr t_exec = manager->create_task(command); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
109 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
110 t_exec->set_inData(0,(char*)in_data + index*in_data_size, in_data_size); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
111 t_exec->set_outData(0,(char*)out_data + index*out_data_size, out_data_size); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
112 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
113 index++; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
114 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
115 if (wait_me != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
116 wait_me->wait_for(t_exec); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
117 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
118 if (wait_i != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
119 t_exec->wait_for(wait_i); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
120 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
121 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
122 t_exec->spawn(); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
123 t_exec->set_cpu(SPE_ANY); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
124 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
125 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
126 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
127 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
128 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
129 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
130 |
393 | 131 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
132 static int |
393 | 133 fix_byte(int size,int fix_byte_size) |
134 { | |
135 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; | |
136 | |
137 return size; | |
138 } | |
139 | |
140 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
141 static st_mmap_t |
393 | 142 my_mmap(char *filename) |
143 { | |
144 | |
145 /*マッピングだよ!*/ | |
146 int fd = -1; | |
147 int map = MAP_PRIVATE; | |
148 st_mmap_t st_mmap; | |
149 struct stat sb; | |
150 | |
151 if ((fd=open(filename,O_RDONLY,0666))==0) { | |
152 fprintf(stderr,"can't open %s\n",filename); | |
153 } | |
154 | |
155 if (fstat(fd,&sb)) { | |
156 fprintf(stderr,"can't fstat %s\n",filename); | |
157 } | |
158 | |
159 printf("file size %d\n",(int)sb.st_size); | |
160 | |
161 /*sizeをページングサイズの倍数にあわせる*/ | |
162 st_mmap.size = fix_byte(sb.st_size,4096); | |
163 | |
394 | 164 printf("fix 4096byte file size %d\n",(int)st_mmap.size); |
393 | 165 |
166 st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); | |
167 if (st_mmap.file_mmap == (caddr_t)-1) { | |
168 fprintf(stderr,"Can't mmap file\n"); | |
169 perror(NULL); | |
170 exit(0); | |
171 } | |
172 | |
173 return st_mmap; | |
174 | |
175 } | |
176 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
177 static void |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
178 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
179 { |
1021 | 180 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
181 if (task_count < array_task_num) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
182 array_task_num = task_count; |
948 | 183 if (task_count<=0) return; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
184 } |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
185 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
186 //static void simple_task_creater(int in_total_size, int out_total_size, |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
187 // int command, int in_data_size, int out_data_size, |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
188 // void *in_data, void *out_data, TaskManager *manager, |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
189 // HTask *wait_i, HTask *wait_me) |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
190 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
191 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
192 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
193 if (use_task_creater) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
194 simple_task_creater(w->file_size, w->division_out_size * w->task_num, TASK_EXEC, w->division_size, w->division_out_size, |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
195 w->file_mmap, w->o_data, manager, w->t_print, 0); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
196 } |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
197 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
198 if (use_task_array) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
199 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
200 int spl = spe_num * array_task_num; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
201 int loop = (task_count + spl - 1) / spl; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
202 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
203 for (int i = 0; i < loop; i += 1) { |
972 | 204 |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
205 if (spl > w->task_num) { |
972 | 206 if (w->task_num >= spe_num) { |
207 array_task_num = w->task_num / spe_num; | |
208 } else { | |
209 | |
210 int task_num = w->task_num; | |
211 | |
212 for (int j = 0; j < task_num; j++) { | |
213 HTask *h_exec = 0; | |
214 int i = w->task_spwaned++; | |
215 | |
216 if (w->size < size) size = w->size; | |
217 | |
218 h_exec = manager->create_task(TASK_EXEC, | |
219 (memaddr)(w->file_mmap + i*w->division_size), size, | |
220 (memaddr)(w->o_data + i*w->out_size), w->division_out_size); | |
221 | |
222 if (all) { | |
223 w->t_print->wait_for(h_exec); | |
224 } else { | |
225 t_next->wait_for(h_exec); | |
226 } | |
227 | |
228 h_exec->set_cpu(SPE_ANY); | |
229 h_exec->spawn(); | |
230 | |
231 w->size -= size; | |
232 w->task_num--; | |
233 | |
234 } | |
235 | |
236 return; | |
237 } | |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
238 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
239 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
240 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
241 HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
242 Task **t_exec = (Task**)manager->allocate(sizeof(Task*)*spe_num); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
243 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
244 for (int k = 0; k < spe_num; k++) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
245 task_array[k] = manager->create_task_array(TASK_EXEC,array_task_num,0,1,1); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
246 t_exec[k] = 0; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
247 if (all) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
248 w->t_print->wait_for(task_array[k]); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
249 } else { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
250 t_next->wait_for(task_array[k]); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
251 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
252 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
253 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
254 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
255 for (int j = 0; j < array_task_num; j++) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
256 for (int k = 0; k < spe_num; k++) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
257 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
258 int a = w->task_spwaned++; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
259 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
260 if (w->size < size) size = w->size; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
261 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
262 t_exec[k] = task_array[k]->next_task_array(TASK_EXEC,t_exec[k]); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
263 t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, size); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
264 t_exec[k]->set_outData(0,w->o_data + a*w->out_size, w->division_out_size); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
265 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
266 w->size -= size; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
267 w->task_num--; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
268 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
269 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
270 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
271 for (int k = 0; k < spe_num; k++) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
272 task_array[k]->spawn_task_array(t_exec[k]->next()); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
273 task_array[k]->set_cpu(SPE_ANY); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
274 task_array[k]->spawn(); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
275 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
276 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
277 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
278 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
279 return; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
280 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
281 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
282 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
283 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
284 for (int i = 0; i < task_count; i += array_task_num) { |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
285 |
1021 | 286 HTask *h_exec = 0; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
287 for (int j = 0; j < array_task_num; j++) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
288 int i = w->task_spwaned++; |
949 | 289 if (w->size < size) size = w->size; |
290 if (size==0) break; | |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
291 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
292 if (use_compat) { |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
293 h_exec = manager->create_task(TASK_EXEC); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
294 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
295 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); |
968 | 296 |
1021 | 297 |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
298 if (all) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
299 w->t_print->wait_for(h_exec); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
300 } else { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
301 t_next->wait_for(h_exec); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
302 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
303 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
304 h_exec->set_cpu(SPE_ANY); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
305 h_exec->spawn(); |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
306 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
307 } else { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
308 h_exec = manager->create_task(TASK_EXEC, |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
309 (memaddr)(w->file_mmap + i*w->division_size), size, |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
310 (memaddr)(w->o_data + i*w->out_size), w->division_out_size); |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
311 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
312 if (all) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
313 w->t_print->wait_for(h_exec); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
314 } else { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
315 t_next->wait_for(h_exec); |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
316 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
317 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
318 h_exec->set_cpu(SPE_ANY); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
319 h_exec->spawn(); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
320 } |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
321 w->size -= size; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
322 w->task_num--; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
323 } |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
324 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
325 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
326 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
327 } |
393 | 328 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
329 /** |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
330 * このTaskは、PPE上で実行されるので、並列に実行されることはない |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
331 * 二つ実行されていて、Task が足りなくなることがないようにしている。 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
332 */ |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
333 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
334 SchedDefineTask1(RUN_TASK_BLOCKS,run16); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
335 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
336 static int |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
337 run16(SchedTask *manager, void *in, void *out) |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
338 { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
339 WordCount *w = *(WordCount **)in; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
340 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
341 if (w->task_num < w->task_blocks) { |
949 | 342 // last case |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
343 if (w->size >= w->division_size) |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
344 run_tasks(manager,w,w->task_num, w->t_print, w->division_size); |
949 | 345 // remaining data |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
346 while (w->size>0) |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
347 run_tasks(manager,w,1, w->t_print, w->size); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
348 // printf("run16 last %d\n",w->task_num); |
949 | 349 } else { |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
350 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
351 (memaddr)&w->self,sizeof(memaddr),0,0); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
352 w->t_print->wait_for(t_next); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
353 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
354 run_tasks(manager,w, w->task_blocks, t_next, w->division_size); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
355 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
356 t_next->spawn(); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
357 // printf("run16 next %d\n",w->task_num); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
358 } |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
359 return 0; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
360 } |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
361 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
362 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
363 static int blocks = 48; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
364 static int division = 16; // in Kbyte |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
365 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
366 static void |
400 | 367 run_start(TaskManager *manager, char *filename) |
393 | 368 { |
369 HTaskPtr t_print; | |
370 | |
371 st_mmap_t st_mmap; | |
372 st_mmap = my_mmap(filename); | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
373 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
374 // bzero(w,sizeof(WordCount)); |
393 | 375 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
376 w->self = w; |
968 | 377 //w->task_blocks = blocks; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
378 w->task_spwaned = 0; |
393 | 379 |
380 /*sizeはdivision_sizeの倍数にしている。*/ | |
949 | 381 w->size = w->file_size = st_mmap.size; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
382 w->file_mmap = st_mmap.file_mmap; |
949 | 383 printf("w %lx\n",(long)w); |
393 | 384 |
385 /* 1task分のデータサイズ(byte) */ | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
386 if (w->size >= 1024*division) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
387 w->division_size = 1024 * division;/*16kbyte*/ |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
388 } else { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
389 w->division_size = w->size; |
393 | 390 } |
391 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
392 printf("dvision_size %d\n",w->division_size); |
393 | 393 |
394 /* "word num" and "line num" */ | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
395 w->status_num = 2; |
393 | 396 /* taskの数 */ |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
397 w->task_num = w->size / w->division_size; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
398 w->task_num = w->task_num + (w->division_size*w->task_num < w->size); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
399 int out_task_num = w->task_num; |
394 | 400 |
968 | 401 if(!all) { |
402 w->task_blocks = blocks; | |
403 } else { | |
404 w->task_blocks = w->task_num; | |
405 } | |
406 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
407 w->out_task_num = out_task_num; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
408 printf("task_num %d\n",w->task_num); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
409 printf("out_task_num %d\n",w->out_task_num); |
394 | 410 |
1007 | 411 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(4byte)を使用 */ |
393 | 412 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
413 w->division_out_size = sizeof(unsigned long long)*4; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
414 int out_size = w->division_out_size*out_task_num; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
415 w->o_data = (unsigned long long *)manager->allocate(out_size); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
416 w->out_size = 4; |
393 | 417 printf("out size %d\n",out_size); |
418 | |
419 /*各SPEの結果を合計して出力するタスク*/ | |
420 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
421 t_print = manager->create_task(TASK_PRINT, |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
422 (memaddr)&w->self,sizeof(memaddr),0,0); |
393 | 423 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
424 w->t_print = t_print; |
783 | 425 |
968 | 426 for(int i = 0;i<1;i++) { |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
427 /* Task を task_blocks ずつ起動する Task */ |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
428 /* serialize されていると仮定する... */ |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
429 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
430 (memaddr)&w->self,sizeof(memaddr),0,0); |
393 | 431 t_print->wait_for(t_exec); |
432 t_exec->spawn(); | |
394 | 433 } |
434 | |
393 | 435 t_print->spawn(); |
436 } | |
437 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
438 static char* |
393 | 439 init(int argc, char **argv) |
440 { | |
441 | |
394 | 442 char *filename = 0; |
393 | 443 |
394 | 444 for (int i = 1; argv[i]; ++i) { |
393 | 445 if (strcmp(argv[i], "-file") == 0) { |
446 filename = argv[i+1]; | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
447 } else if (strcmp(argv[i], "-division") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
448 division = atoi(argv[i+1]); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
449 } else if (strcmp(argv[i], "-block") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
450 blocks = atoi(argv[i+1]); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
451 } else if (strcmp(argv[i], "-a") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
452 // create task all at once |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
453 all = 1; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
454 } else if (strcmp(argv[i], "-c") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
455 use_task_array = 0; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
456 use_compat = 1; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
457 } else if (strcmp(argv[i], "-s") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
458 use_task_array = 0; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
459 use_compat = 0; |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
460 } else if (strcmp(argv[i], "-t") == 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
461 use_task_creater = 1; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
462 use_task_array = 0; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
463 use_compat = 0; |
967
daab1b74b32d
add anum option in WordCount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
950
diff
changeset
|
464 } else if (strcmp(argv[i], "-anum") == 0) { |
daab1b74b32d
add anum option in WordCount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
950
diff
changeset
|
465 array_task_num = atoi(argv[i+1]); |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
466 } else if (strcmp(argv[i], "-cpu") == 0) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
467 spe_num = atoi(argv[i+1]); |
1083 | 468 if (spe_num==0) spe_num = 1; |
393 | 469 } |
470 } | |
400 | 471 if (filename==0) { |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
472 puts(usr_help_str); |
400 | 473 exit(1); |
474 } | |
393 | 475 |
476 return filename; | |
477 } | |
478 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
479 |
393 | 480 int |
400 | 481 TMmain(TaskManager *manager, int argc, char *argv[]) |
393 | 482 { |
483 | |
394 | 484 char *filename = 0; |
485 filename = init(argc, argv); | |
393 | 486 |
487 if (filename < 0) { | |
488 return -1; | |
489 } | |
490 | |
491 task_init(); | |
400 | 492 run_start(manager, filename); |
393 | 493 |
494 return 0; | |
495 } | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
496 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
497 /* end */ |