Mercurial > hg > Members > kono > Cerium
annotate example/word_count/main.cc @ 968:0a6c5ee89a4c
fix wordcount
author | Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 09 Aug 2010 00:09:00 +0900 |
parents | 3e1c218da048 |
children | 33630c6ff445 |
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
a8b6ee80c108
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
a8b6ee80c108
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
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
16 int all = 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
17 int use_task_array = 1; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
18 int use_compat = 0; |
967
3e1c218da048
add anum option in WordCount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
950
diff
changeset
|
19 int array_task_num = 8; |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
20 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
21 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-file filename]\n"; |
393 | 22 |
23 typedef struct { | |
24 caddr_t file_mmap; | |
25 off_t size; | |
26 } st_mmap_t; | |
27 | |
28 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
29 |
393 | 30 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
31 static int |
393 | 32 fix_byte(int size,int fix_byte_size) |
33 { | |
34 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; | |
35 | |
36 return size; | |
37 } | |
38 | |
39 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
40 static st_mmap_t |
393 | 41 my_mmap(char *filename) |
42 { | |
43 | |
44 /*マッピングだよ!*/ | |
45 int fd = -1; | |
46 int map = MAP_PRIVATE; | |
47 st_mmap_t st_mmap; | |
48 struct stat sb; | |
49 | |
50 if ((fd=open(filename,O_RDONLY,0666))==0) { | |
51 fprintf(stderr,"can't open %s\n",filename); | |
52 } | |
53 | |
54 if (fstat(fd,&sb)) { | |
55 fprintf(stderr,"can't fstat %s\n",filename); | |
56 } | |
57 | |
58 printf("file size %d\n",(int)sb.st_size); | |
59 | |
60 /*sizeをページングサイズの倍数にあわせる*/ | |
61 st_mmap.size = fix_byte(sb.st_size,4096); | |
62 | |
394 | 63 printf("fix 4096byte file size %d\n",(int)st_mmap.size); |
393 | 64 |
65 st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); | |
66 if (st_mmap.file_mmap == (caddr_t)-1) { | |
67 fprintf(stderr,"Can't mmap file\n"); | |
68 perror(NULL); | |
69 exit(0); | |
70 } | |
71 | |
72 return st_mmap; | |
73 | |
74 } | |
75 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
76 static void |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
77 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
78 { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
79 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
80 if (task_count < array_task_num) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
81 array_task_num = task_count; |
948 | 82 if (task_count<=0) return; |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
83 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
84 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
85 for (int i = 0; i < task_count; i += array_task_num) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
86 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
87 HTask *task_array; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
88 if (use_task_array) { |
950
e0908a8955cd
word count size fix for task array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
949
diff
changeset
|
89 int task_num = (w->size+size-1)/size; |
e0908a8955cd
word count size fix for task array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
949
diff
changeset
|
90 if (task_num>array_task_num) task_num = array_task_num; |
e0908a8955cd
word count size fix for task array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
949
diff
changeset
|
91 task_array = manager->create_task_array(TASK_EXEC,task_num,0,1,1); |
968 | 92 if (!all) { |
93 t_next->wait_for(task_array); | |
94 } else { | |
95 w->t_print->wait_for(task_array); | |
96 } | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
97 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
98 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
99 Task *t_exec = 0; |
948 | 100 HTask *h_exec = 0; |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
101 for (int j = 0; j < array_task_num; j++) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
102 int i = w->task_spwaned++; |
949 | 103 if (w->size < size) size = w->size; |
104 if (size==0) break; | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
105 if (use_task_array) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
106 t_exec = task_array->next_task_array(TASK_EXEC,t_exec); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
107 t_exec->set_inData(0,w->file_mmap + i*w->division_size, size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
108 t_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
109 } else if (use_compat) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
110 h_exec = manager->create_task(TASK_EXEC); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
111 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
112 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); |
968 | 113 |
114 t_next->wait_for(h_exec); | |
115 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
116 h_exec->set_cpu(SPE_ANY); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
117 h_exec->spawn(); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
118 } else { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
119 h_exec = manager->create_task(TASK_EXEC, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
120 (memaddr)(w->file_mmap + i*w->division_size), size, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
121 (memaddr)(w->o_data + i*w->out_size), w->division_out_size); |
968 | 122 t_next->wait_for(h_exec); |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
123 h_exec->set_cpu(SPE_ANY); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
124 h_exec->spawn(); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
125 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
126 w->size -= size; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
127 w->task_num--; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
128 } |
948 | 129 if (use_task_array) { |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
130 task_array->spawn_task_array(t_exec->next()); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
131 task_array->set_cpu(SPE_ANY); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
132 task_array->spawn(); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
133 } else { |
968 | 134 //if (!all) t_next->wait_for(h_exec); |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
135 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
136 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
137 } |
393 | 138 |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
139 /** |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
140 * このTaskは、PPE上で実行されるので、並列に実行されることはない |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
141 * 二つ実行されていて、Task が足りなくなることがないようにしている。 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
142 */ |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
143 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
144 SchedDefineTask1(RUN_TASK_BLOCKS,run16); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
145 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
146 static int |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
147 run16(SchedTask *manager, void *in, void *out) |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
148 { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
149 WordCount *w = *(WordCount **)in; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
150 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
151 if (w->task_num < w->task_blocks) { |
949 | 152 // last case |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
153 if (w->size >= w->division_size) |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
154 run_tasks(manager,w,w->task_num, w->t_print, w->division_size); |
949 | 155 // remaining data |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
156 while (w->size>0) |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
157 run_tasks(manager,w,1, w->t_print, w->size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
158 // printf("run16 last %d\n",w->task_num); |
949 | 159 } else { |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
160 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
161 (memaddr)&w->self,sizeof(memaddr),0,0); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
162 w->t_print->wait_for(t_next); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
163 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
164 run_tasks(manager,w, w->task_blocks, t_next, w->division_size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
165 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
166 t_next->spawn(); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
167 // printf("run16 next %d\n",w->task_num); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
168 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
169 return 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
170 } |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
171 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
172 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
173 static int blocks = 48; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
174 static int division = 16; // in Kbyte |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
175 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
176 static void |
400 | 177 run_start(TaskManager *manager, char *filename) |
393 | 178 { |
179 HTaskPtr t_print; | |
180 | |
181 st_mmap_t st_mmap; | |
182 st_mmap = my_mmap(filename); | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
183 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
184 // bzero(w,sizeof(WordCount)); |
393 | 185 |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
186 w->self = w; |
968 | 187 //w->task_blocks = blocks; |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
188 w->task_spwaned = 0; |
393 | 189 |
190 /*sizeはdivision_sizeの倍数にしている。*/ | |
949 | 191 w->size = w->file_size = st_mmap.size; |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
192 w->file_mmap = st_mmap.file_mmap; |
949 | 193 printf("w %lx\n",(long)w); |
393 | 194 |
195 /* 1task分のデータサイズ(byte) */ | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
196 if (w->size >= 1024*division) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
197 w->division_size = 1024 * division;/*16kbyte*/ |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
198 } else { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
199 w->division_size = w->size; |
393 | 200 } |
201 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
202 printf("dvision_size %d\n",w->division_size); |
393 | 203 |
204 /* "word num" and "line num" */ | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
205 w->status_num = 2; |
393 | 206 /* taskの数 */ |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
207 w->task_num = w->size / w->division_size; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
208 w->task_num = w->task_num + (w->division_size*w->task_num < w->size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
209 int out_task_num = w->task_num; |
394 | 210 |
968 | 211 if(!all) { |
212 w->task_blocks = blocks; | |
213 } else { | |
214 w->task_blocks = w->task_num; | |
215 } | |
216 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
217 w->out_task_num = out_task_num; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
218 printf("task_num %d\n",w->task_num); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
219 printf("out_task_num %d\n",w->out_task_num); |
394 | 220 |
393 | 221 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */ |
222 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
223 w->division_out_size = sizeof(unsigned long long)*4; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
224 int out_size = w->division_out_size*out_task_num; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
225 w->o_data = (unsigned long long *)manager->allocate(out_size); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
226 w->out_size = 4; |
393 | 227 printf("out size %d\n",out_size); |
228 | |
229 /*各SPEの結果を合計して出力するタスク*/ | |
230 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
231 t_print = manager->create_task(TASK_PRINT, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
232 (memaddr)&w->self,sizeof(memaddr),0,0); |
393 | 233 |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
234 w->t_print = t_print; |
783 | 235 |
968 | 236 for(int i = 0;i<1;i++) { |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
237 /* Task を task_blocks ずつ起動する Task */ |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
238 /* serialize されていると仮定する... */ |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
239 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
240 (memaddr)&w->self,sizeof(memaddr),0,0); |
393 | 241 t_print->wait_for(t_exec); |
242 t_exec->spawn(); | |
394 | 243 } |
244 | |
393 | 245 t_print->spawn(); |
246 } | |
247 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
248 static char* |
393 | 249 init(int argc, char **argv) |
250 { | |
251 | |
394 | 252 char *filename = 0; |
393 | 253 |
394 | 254 for (int i = 1; argv[i]; ++i) { |
393 | 255 if (strcmp(argv[i], "-file") == 0) { |
256 filename = argv[i+1]; | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
257 } else if (strcmp(argv[i], "-division") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
258 division = atoi(argv[i+1]); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
259 } else if (strcmp(argv[i], "-block") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
260 blocks = atoi(argv[i+1]); |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
261 } else if (strcmp(argv[i], "-a") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
262 // create task all at once |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
263 all = 1; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
264 } else if (strcmp(argv[i], "-c") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
265 use_task_array = 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
266 use_compat = 1; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
267 } else if (strcmp(argv[i], "-s") == 0) { |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
268 use_task_array = 0; |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
269 use_compat = 0; |
967
3e1c218da048
add anum option in WordCount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
950
diff
changeset
|
270 } else if (strcmp(argv[i], "-anum") == 0) { |
3e1c218da048
add anum option in WordCount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
950
diff
changeset
|
271 array_task_num = atoi(argv[i+1]); |
393 | 272 } |
273 } | |
400 | 274 if (filename==0) { |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
275 puts(usr_help_str); |
400 | 276 exit(1); |
277 } | |
393 | 278 |
279 return filename; | |
280 } | |
281 | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
282 |
393 | 283 int |
400 | 284 TMmain(TaskManager *manager, int argc, char *argv[]) |
393 | 285 { |
286 | |
394 | 287 char *filename = 0; |
288 filename = init(argc, argv); | |
393 | 289 |
290 if (filename < 0) { | |
291 return -1; | |
292 } | |
293 | |
294 task_init(); | |
400 | 295 run_start(manager, filename); |
393 | 296 |
297 return 0; | |
298 } | |
946
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
299 |
a8b6ee80c108
unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
797
diff
changeset
|
300 /* end */ |