Mercurial > hg > Game > Cerium
annotate example/word_count_test/main.cc @ 672:27fec8c70c9c draft
add profiling code
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 05 Dec 2009 20:20:08 +0900 |
parents | 87040ec6b5f6 |
children | 5e5e8eb8da5a |
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 |
672 | 135 static int profile = 0; |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
136 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
137 static void |
658 | 138 run_start(TaskManager *manager, char *filename) |
139 { | |
140 HTaskPtr t_print; | |
141 | |
142 st_mmap_t st_mmap; | |
143 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
|
144 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); |
664 | 145 // bzero(w,sizeof(WordCount)); |
658 | 146 |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
147 w->self = w; |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
148 w->task_blocks = blocks; |
664 | 149 w->task_spwaned = 0; |
658 | 150 |
151 /*sizeはdivision_sizeの倍数にしている。*/ | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
152 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
|
153 w->file_mmap = st_mmap.file_mmap; |
658 | 154 |
155 /* 1task分のデータサイズ(byte) */ | |
666 | 156 if (w->size >= 1024*division) { |
157 w->division_size = 1024 * division;/*16kbyte*/ | |
158 } else { | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
159 w->division_size = w->size; |
658 | 160 } |
161 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
162 printf("dvision_size %d\n",w->division_size); |
658 | 163 |
164 /* "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
|
165 w-> status_num = 2; |
658 | 166 /* taskの数 */ |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
167 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
|
168 int out_task_num = w->task_num + (w->division_size*w->task_num < w->size); |
658 | 169 |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
170 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
|
171 printf("task_num %d\n",w->task_num); |
658 | 172 |
173 /* 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
|
174 |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
175 #ifdef SIMPLE_TASK |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 w-> out_size = 4; |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
180 #else |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
181 w-> division_out_size = 16; |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
182 int out_size = w->division_out_size*out_task_num; |
658 | 183 /* out用のデータのサイズ。*/ |
669
1d9608e6965f
fix non SIMPLE_TASK code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
667
diff
changeset
|
184 caddr_t p = (caddr_t) manager->allocate(out_size*2); |
1d9608e6965f
fix non SIMPLE_TASK code
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
667
diff
changeset
|
185 w->o_data = (unsigned long long*)p; |
664 | 186 //bzero(w->o_data,out_size); |
658 | 187 |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
188 w-> pad = 2; |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
189 w->head_tail_flag = (unsigned long long*)(p+out_size); |
664 | 190 // bzero(w->head_tail_flag,out_size); |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
191 #endif |
658 | 192 printf("out size %d\n",out_size); |
193 | |
194 /*各SPEの結果を合計して出力するタスク*/ | |
195 | |
672 | 196 if (profile) { |
197 manager->start_profile(); | |
198 } | |
199 | |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
200 #ifdef SIMPLE_TASK |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
201 t_print = manager->create_task(TASK_PRINT, |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
202 (memaddr)&w->self,sizeof(memaddr),0,0); |
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
203 #else |
658 | 204 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
|
205 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
|
206 t_print->add_inData(w->head_tail_flag, out_size); |
658 | 207 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
|
208 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
|
209 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
|
210 t_print->add_param(w->pad); |
667
ae1d1eebf9ff
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
211 #endif |
658 | 212 |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
213 w->t_print = t_print; |
658 | 214 |
670 | 215 for(int i = 0;i<1;i++) { |
216 /* Task を task_blocks ずつ起動する Task */ | |
217 /* serialize されていると仮定する... */ | |
218 #ifdef SIMPLE_TASK | |
219 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, | |
220 (memaddr)&w->self,sizeof(memaddr),0,0); | |
221 #else | |
222 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS); | |
223 t_exec->set_param(0,(void*)w); | |
224 #endif | |
225 t_exec->spawn(); | |
226 t_print->wait_for(t_exec); | |
227 } | |
658 | 228 |
229 t_print->spawn(); | |
230 } | |
231 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
232 static char* |
658 | 233 init(int argc, char **argv) |
234 { | |
235 | |
236 char *filename = 0; | |
237 | |
238 for (int i = 1; argv[i]; ++i) { | |
239 if (strcmp(argv[i], "-file") == 0) { | |
240 filename = argv[i+1]; | |
666 | 241 } else if (strcmp(argv[i], "-division") == 0) { |
242 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
|
243 } 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
|
244 blocks = atoi(argv[i+1]); |
672 | 245 } else if (strcmp(argv[i], "-p") == 0) { |
246 profile = 1; | |
658 | 247 } |
248 } | |
249 if (filename==0) { | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
250 printf("usage: %s [-block 10] -file filename\n",argv[0]); |
658 | 251 exit(1); |
252 } | |
253 | |
254 return filename; | |
255 } | |
256 | |
672 | 257 static void |
258 myTMend(TaskManager *manager) | |
259 { | |
260 manager->show_profile(); | |
261 } | |
262 | |
658 | 263 int |
264 TMmain(TaskManager *manager, int argc, char *argv[]) | |
265 { | |
266 | |
267 char *filename = 0; | |
268 filename = init(argc, argv); | |
269 | |
270 if (filename < 0) { | |
271 return -1; | |
272 } | |
672 | 273 manager->set_TMend(myTMend); |
658 | 274 |
275 task_init(); | |
276 run_start(manager, filename); | |
277 | |
278 return 0; | |
279 } | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
280 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
281 /* end */ |