Mercurial > hg > Game > Cerium
annotate example/word_count_test/main.cc @ 667:ae1d1eebf9ff draft
SimpeTask WordCount Worked.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2009 04:23:36 +0900 |
parents | f02b3338b91b |
children | 1d9608e6965f |
rev | line source |
---|---|
658 | 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" | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
10 #include "SchedTask.h" |
658 | 11 #include "Func.h" |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
12 #include "WordCount.h" |
658 | 13 |
14 extern void task_init(); | |
15 | |
16 const char *usr_help_str = "Usage: ./word_count [-cpu spe_num] [-file filename]\n"; | |
17 | |
18 typedef struct { | |
19 caddr_t file_mmap; | |
20 off_t size; | |
21 } st_mmap_t; | |
22 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
23 |
658 | 24 |
25 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
26 static int |
658 | 27 fix_byte(int size,int fix_byte_size) |
28 { | |
29 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; | |
30 | |
31 return size; | |
32 } | |
33 | |
34 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
35 static st_mmap_t |
658 | 36 my_mmap(char *filename) |
37 { | |
38 | |
39 /*マッピングだよ!*/ | |
40 int fd = -1; | |
41 int map = MAP_PRIVATE; | |
42 st_mmap_t st_mmap; | |
43 struct stat sb; | |
44 | |
45 if ((fd=open(filename,O_RDONLY,0666))==0) { | |
46 fprintf(stderr,"can't open %s\n",filename); | |
47 } | |
48 | |
49 if (fstat(fd,&sb)) { | |
50 fprintf(stderr,"can't fstat %s\n",filename); | |
51 } | |
52 | |
53 printf("file size %d\n",(int)sb.st_size); | |
54 | |
55 /*sizeをページングサイズの倍数にあわせる*/ | |
56 st_mmap.size = fix_byte(sb.st_size,4096); | |
57 | |
58 printf("fix 4096byte file size %d\n",(int)st_mmap.size); | |
59 | |
60 st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); | |
61 if (st_mmap.file_mmap == (caddr_t)-1) { | |
62 fprintf(stderr,"Can't mmap file\n"); | |
63 perror(NULL); | |
64 exit(0); | |
65 } | |
66 | |
67 return st_mmap; | |
68 | |
69 } | |
70 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
71 static void |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
72 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
73 { |
664 | 74 for (int j = 0; j < task_count && w->size>0; j++) { |
75 int i = w->task_spwaned++; | |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
76 #ifdef SIMPLE_TASK |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
77 // printf("div %0x\n", (w->file_mmap + i*w->division_size)); |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
78 HTaskPtr t_exec = manager->create_task(TASK_EXEC, |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
79 (memaddr)(w->file_mmap + i*w->division_size), size, |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
80 (memaddr)(w->o_data + i*w->out_size), w->division_out_size); |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
81 #else |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
82 HTaskPtr t_exec = manager->create_task(TASK_EXEC); |
664 | 83 if (size>w->size) size = w->size; |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
84 t_exec->add_inData(w->file_mmap + i*w->division_size, size); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
85 t_exec->add_outData(w->o_data + i*w->status_num, w->division_out_size); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
86 t_exec->add_outData(w->head_tail_flag + i*w->pad, w->division_out_size); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
87 t_exec->add_param(size); |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
88 #endif |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
89 t_exec->set_cpu(SPE_ANY); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
90 t_next->wait_for(t_exec); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
91 t_exec->spawn(); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
92 w->size -= size; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
93 w->task_num--; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
94 } |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
95 } |
658 | 96 |
664 | 97 SchedDefineTask1(RUN_TASK_BLOCKS,run16); |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
98 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
99 static int |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
100 run16(SchedTask *manager, void *in, void *out) |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
101 { |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
102 #ifdef SIMPLE_TASK |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
103 WordCount *w = *(WordCount **)in; |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
104 #else |
664 | 105 WordCount *w = (WordCount *)manager->get_param(0); |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
106 #endif |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
107 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
108 if (w->task_num < w->task_blocks) { |
664 | 109 if (w->size >= w->division_size) |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
110 run_tasks(manager,w,w->task_blocks, w->t_print, w->division_size); |
664 | 111 while (w->size>0) |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
112 run_tasks(manager,w,1, w->t_print, w->size); |
664 | 113 // printf("run16 last %d\n",w->task_num); |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
114 } else { |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
115 #ifdef SIMPLE_TASK |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
116 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
117 (memaddr)&w->self,sizeof(memaddr),0,0); |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
118 #else |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
119 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
120 t_next->set_param(0,(void*)w); |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
121 #endif |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
122 w->t_print->wait_for(t_next); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
123 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
124 run_tasks(manager,w, w->task_blocks, t_next, w->division_size); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
125 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
126 t_next->spawn(); |
664 | 127 // printf("run16 next %d\n",w->task_num); |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
128 } |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
129 return 0; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
130 } |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
131 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
132 |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
133 static int blocks = 48; |
666 | 134 static int division = 16; // in Kbyte |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
135 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
136 static void |
658 | 137 run_start(TaskManager *manager, char *filename) |
138 { | |
139 HTaskPtr t_print; | |
140 | |
141 st_mmap_t st_mmap; | |
142 st_mmap = my_mmap(filename); | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
143 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); |
664 | 144 // bzero(w,sizeof(WordCount)); |
658 | 145 |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
146 w->self = w; |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
147 w->task_blocks = blocks; |
664 | 148 w->task_spwaned = 0; |
658 | 149 |
150 /*sizeはdivision_sizeの倍数にしている。*/ | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
151 w->size = st_mmap.size; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
152 w->file_mmap = st_mmap.file_mmap; |
658 | 153 |
154 /* 1task分のデータサイズ(byte) */ | |
666 | 155 if (w->size >= 1024*division) { |
156 w->division_size = 1024 * division;/*16kbyte*/ | |
157 } else { | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
158 w->division_size = w->size; |
658 | 159 } |
160 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
161 printf("dvision_size %d\n",w->division_size); |
658 | 162 |
163 /* "word num" and "line num" */ | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
164 w-> status_num = 2; |
658 | 165 /* taskの数 */ |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
166 w-> task_num = w->size / w->division_size; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
167 int out_task_num = w->task_num + (w->division_size*w->task_num < w->size); |
658 | 168 |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
169 w->out_task_num = out_task_num; |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
170 printf("task_num %d\n",w->task_num); |
658 | 171 |
172 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */ | |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
173 |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
174 #ifdef SIMPLE_TASK |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
175 w-> division_out_size = sizeof(unsigned long long)*4; |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
176 int out_size = w->division_out_size*out_task_num; |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
177 w->o_data = (unsigned long long *)manager->allocate(out_size); |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
178 w-> out_size = 4; |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
179 #else |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
180 w-> division_out_size = 16; |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
181 int out_size = w->division_out_size*out_task_num; |
658 | 182 /* out用のデータのサイズ。*/ |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
183 caddr_t p = manager->allocate(out_size*2); |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
184 w->o_data = (unsigned long long*)p |
664 | 185 //bzero(w->o_data,out_size); |
658 | 186 |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
187 w-> pad = 2; |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
188 w->head_tail_flag = (unsigned long long*)(p+out_size); |
664 | 189 // bzero(w->head_tail_flag,out_size); |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
190 #endif |
658 | 191 printf("out size %d\n",out_size); |
192 | |
193 /*各SPEの結果を合計して出力するタスク*/ | |
194 | |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
195 #ifdef SIMPLE_TASK |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
196 t_print = manager->create_task(TASK_PRINT, |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
197 (memaddr)&w->self,sizeof(memaddr),0,0); |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
198 #else |
658 | 199 t_print = manager->create_task(TASK_PRINT); |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
200 t_print->add_inData(w->o_data, out_size); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
201 t_print->add_inData(w->head_tail_flag, out_size); |
658 | 202 t_print->add_param(out_task_num); |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
203 t_print->add_param(w->status_num); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
204 t_print->add_param(out_task_num); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
205 t_print->add_param(w->pad); |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
206 #endif |
658 | 207 |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
208 w->t_print = t_print; |
658 | 209 |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
210 /* Task を task_blocks ずつ起動する Task */ |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
211 #ifdef SIMPLE_TASK |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
212 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
213 (memaddr)&w->self,sizeof(memaddr),0,0); |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
214 #else |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
215 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
216 t_exec->set_param(0,(void*)w); |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
217 #endif |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
218 t_exec->spawn(); |
658 | 219 |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
220 t_print->wait_for(t_exec); |
658 | 221 t_print->spawn(); |
222 } | |
223 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
224 static char* |
658 | 225 init(int argc, char **argv) |
226 { | |
227 | |
228 char *filename = 0; | |
229 | |
230 for (int i = 1; argv[i]; ++i) { | |
231 if (strcmp(argv[i], "-file") == 0) { | |
232 filename = argv[i+1]; | |
666 | 233 } else if (strcmp(argv[i], "-division") == 0) { |
234 division = atoi(argv[i+1]); | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
235 } else if (strcmp(argv[i], "-block") == 0) { |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
236 blocks = atoi(argv[i+1]); |
658 | 237 } |
238 } | |
239 if (filename==0) { | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
240 printf("usage: %s [-block 10] -file filename\n",argv[0]); |
658 | 241 exit(1); |
242 } | |
243 | |
244 return filename; | |
245 } | |
246 | |
247 int | |
248 TMmain(TaskManager *manager, int argc, char *argv[]) | |
249 { | |
250 | |
251 char *filename = 0; | |
252 filename = init(argc, argv); | |
253 | |
254 if (filename < 0) { | |
255 return -1; | |
256 } | |
257 | |
258 task_init(); | |
259 run_start(manager, filename); | |
260 | |
261 return 0; | |
262 } | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
263 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
264 /* end */ |