Mercurial > hg > Game > Cerium
annotate example/word_count/main.cc @ 1130:5addc6c1d5c4 draft
fix.
author | root@dolphins.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Sun, 13 Feb 2011 22:34:44 +0900 |
parents | 2a63ba2c9506 |
children | f0808a329663 |
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 if (use_task_creater) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
187 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
|
188 w->file_mmap, w->o_data, manager, w->t_print, 0); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
189 } |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
190 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
191 if (use_task_array) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
192 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
193 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
|
194 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
|
195 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
196 for (int i = 0; i < loop; i += 1) { |
972 | 197 |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
198 if (spl > w->task_num) { |
972 | 199 if (w->task_num >= spe_num) { |
200 array_task_num = w->task_num / spe_num; | |
201 } else { | |
202 | |
203 int task_num = w->task_num; | |
204 | |
205 for (int j = 0; j < task_num; j++) { | |
206 HTask *h_exec = 0; | |
207 int i = w->task_spwaned++; | |
208 | |
209 if (w->size < size) size = w->size; | |
210 | |
211 h_exec = manager->create_task(TASK_EXEC, | |
212 (memaddr)(w->file_mmap + i*w->division_size), size, | |
213 (memaddr)(w->o_data + i*w->out_size), w->division_out_size); | |
214 | |
215 if (all) { | |
216 w->t_print->wait_for(h_exec); | |
217 } else { | |
218 t_next->wait_for(h_exec); | |
219 } | |
220 | |
221 h_exec->set_cpu(SPE_ANY); | |
222 h_exec->spawn(); | |
223 | |
224 w->size -= size; | |
225 w->task_num--; | |
226 | |
227 } | |
228 | |
229 return; | |
230 } | |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
231 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
232 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
233 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
234 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
|
235 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
|
236 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
237 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
|
238 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
|
239 t_exec[k] = 0; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
240 if (all) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
241 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
|
242 } else { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
243 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
|
244 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
245 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
246 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
247 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
248 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
|
249 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
|
250 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
251 int a = w->task_spwaned++; |
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 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
|
254 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
259 w->size -= size; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
260 w->task_num--; |
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 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
263 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 task_array[k]->spawn(); |
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 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
272 return; |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
273 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
274 } |
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 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
277 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
|
278 |
1021 | 279 HTask *h_exec = 0; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
280 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
|
281 int i = w->task_spwaned++; |
949 | 282 if (w->size < size) size = w->size; |
283 if (size==0) break; | |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
284 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
285 if (use_compat) { |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
286 h_exec = manager->create_task(TASK_EXEC); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
287 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
|
288 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); |
968 | 289 |
1021 | 290 |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
291 if (all) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
292 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
|
293 } else { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
294 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
|
295 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
296 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
297 h_exec->set_cpu(SPE_ANY); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
298 h_exec->spawn(); |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
299 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
300 } else { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
301 h_exec = manager->create_task(TASK_EXEC, |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
302 (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
|
303 (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
|
304 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
305 if (all) { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
306 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
|
307 } else { |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
308 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
|
309 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
310 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
311 h_exec->set_cpu(SPE_ANY); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
312 h_exec->spawn(); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
313 } |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
314 w->size -= size; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
315 w->task_num--; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
316 } |
970
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
317 |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
318 } |
1a4849b2acad
change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
968
diff
changeset
|
319 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
320 } |
393 | 321 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
322 /** |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
323 * このTaskは、PPE上で実行されるので、並列に実行されることはない |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
324 * 二つ実行されていて、Task が足りなくなることがないようにしている。 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
325 */ |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
326 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
327 SchedDefineTask1(RUN_TASK_BLOCKS,run16); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
328 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
329 static int |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
330 run16(SchedTask *manager, void *in, void *out) |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
331 { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
332 WordCount *w = *(WordCount **)in; |
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 if (w->task_num < w->task_blocks) { |
949 | 335 // last case |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
336 if (w->size >= w->division_size) |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
337 run_tasks(manager,w,w->task_num, w->t_print, w->division_size); |
949 | 338 // remaining data |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
339 while (w->size>0) |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
340 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
|
341 // printf("run16 last %d\n",w->task_num); |
949 | 342 } else { |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
343 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
|
344 (memaddr)&w->self,sizeof(memaddr),0,0); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
345 w->t_print->wait_for(t_next); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
346 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
347 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
|
348 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
349 t_next->spawn(); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
350 // 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
|
351 } |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
352 return 0; |
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 |
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 static int blocks = 48; |
1123 | 357 //static int blocks = 31 * 6 * 24; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
358 static int division = 16; // in Kbyte |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
359 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
360 static void |
400 | 361 run_start(TaskManager *manager, char *filename) |
393 | 362 { |
363 HTaskPtr t_print; | |
364 | |
365 st_mmap_t st_mmap; | |
366 st_mmap = my_mmap(filename); | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
367 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
368 // bzero(w,sizeof(WordCount)); |
393 | 369 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
370 w->self = w; |
968 | 371 //w->task_blocks = blocks; |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
372 w->task_spwaned = 0; |
393 | 373 |
374 /*sizeはdivision_sizeの倍数にしている。*/ | |
949 | 375 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
|
376 w->file_mmap = st_mmap.file_mmap; |
949 | 377 printf("w %lx\n",(long)w); |
393 | 378 |
379 /* 1task分のデータサイズ(byte) */ | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
380 if (w->size >= 1024*division) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
381 w->division_size = 1024 * division;/*16kbyte*/ |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
382 } else { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
383 w->division_size = w->size; |
393 | 384 } |
385 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
386 printf("dvision_size %d\n",w->division_size); |
393 | 387 |
388 /* "word num" and "line num" */ | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
389 w->status_num = 2; |
393 | 390 /* taskの数 */ |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
391 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
|
392 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
|
393 int out_task_num = w->task_num; |
394 | 394 |
968 | 395 if(!all) { |
396 w->task_blocks = blocks; | |
397 } else { | |
398 w->task_blocks = w->task_num; | |
399 } | |
400 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
401 w->out_task_num = out_task_num; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
402 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
|
403 printf("out_task_num %d\n",w->out_task_num); |
394 | 404 |
1007 | 405 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(4byte)を使用 */ |
393 | 406 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 w->out_size = 4; |
393 | 411 printf("out size %d\n",out_size); |
412 | |
413 /*各SPEの結果を合計して出力するタスク*/ | |
414 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
415 t_print = manager->create_task(TASK_PRINT, |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
416 (memaddr)&w->self,sizeof(memaddr),0,0); |
393 | 417 |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
418 w->t_print = t_print; |
783 | 419 |
1123 | 420 for(int i = 0;i<20;i++) { |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
421 /* Task を task_blocks ずつ起動する Task */ |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
422 /* serialize されていると仮定する... */ |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
423 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
|
424 (memaddr)&w->self,sizeof(memaddr),0,0); |
393 | 425 t_print->wait_for(t_exec); |
426 t_exec->spawn(); | |
394 | 427 } |
428 | |
393 | 429 t_print->spawn(); |
430 } | |
431 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
432 static char* |
393 | 433 init(int argc, char **argv) |
434 { | |
435 | |
394 | 436 char *filename = 0; |
393 | 437 |
394 | 438 for (int i = 1; argv[i]; ++i) { |
393 | 439 if (strcmp(argv[i], "-file") == 0) { |
440 filename = argv[i+1]; | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
441 } else if (strcmp(argv[i], "-division") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
442 division = atoi(argv[i+1]); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
443 } else if (strcmp(argv[i], "-block") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
444 blocks = atoi(argv[i+1]); |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
445 } else if (strcmp(argv[i], "-a") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
446 // create task all at once |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
447 all = 1; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
448 } else if (strcmp(argv[i], "-c") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
449 use_task_array = 0; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
450 use_compat = 1; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
451 } else if (strcmp(argv[i], "-s") == 0) { |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
452 use_task_array = 0; |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
453 use_compat = 0; |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
454 } else if (strcmp(argv[i], "-t") == 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
455 use_task_creater = 1; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
456 use_task_array = 0; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1021
diff
changeset
|
457 use_compat = 0; |
967
daab1b74b32d
add anum option in WordCount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
950
diff
changeset
|
458 } 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
|
459 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
|
460 } 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
|
461 spe_num = atoi(argv[i+1]); |
1083 | 462 if (spe_num==0) spe_num = 1; |
393 | 463 } |
464 } | |
400 | 465 if (filename==0) { |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
466 puts(usr_help_str); |
400 | 467 exit(1); |
468 } | |
393 | 469 |
470 return filename; | |
471 } | |
472 | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
473 |
393 | 474 int |
400 | 475 TMmain(TaskManager *manager, int argc, char *argv[]) |
393 | 476 { |
477 | |
394 | 478 char *filename = 0; |
479 filename = init(argc, argv); | |
393 | 480 |
481 if (filename < 0) { | |
482 return -1; | |
483 } | |
484 | |
485 task_init(); | |
400 | 486 run_start(manager, filename); |
393 | 487 |
488 return 0; | |
489 } | |
946
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
490 |
852ed17d8af1
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
491 /* end */ |