Mercurial > hg > Members > kono > Cerium
annotate example/word_count_test/main.cc @ 674:bde5f13adf10
fix many task example (sort).
Dummy task is now system supported.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 06 Dec 2009 00:54:10 +0900 |
parents | d9111086b2c4 |
children | f725c6455d19 |
rev | line source |
---|---|
661 | 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
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
10 #include "SchedTask.h" |
661 | 11 #include "Func.h" |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
12 #include "WordCount.h" |
661 | 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
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
23 |
661 | 24 |
25 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ | |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
26 static int |
661 | 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
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
35 static st_mmap_t |
661 | 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
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
71 static void |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
72 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
73 { |
664 | 74 for (int j = 0; j < task_count && w->size>0; j++) { |
75 int i = w->task_spwaned++; | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
76 #ifdef SIMPLE_TASK |
d753b4f6b129
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)); |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
78 HTaskPtr t_exec = manager->create_task(TASK_EXEC, |
d753b4f6b129
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, |
d753b4f6b129
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); |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
81 #else |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
82 HTaskPtr t_exec = manager->create_task(TASK_EXEC); |
664 | 83 if (size>w->size) size = w->size; |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
84 t_exec->add_inData(w->file_mmap + i*w->division_size, size); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
85 t_exec->add_outData(w->o_data + i*w->status_num, w->division_out_size); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
86 t_exec->add_outData(w->head_tail_flag + i*w->pad, w->division_out_size); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
87 t_exec->add_param(size); |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
88 #endif |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
89 t_exec->set_cpu(SPE_ANY); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
90 t_next->wait_for(t_exec); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
91 t_exec->spawn(); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
92 w->size -= size; |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
93 w->task_num--; |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
94 } |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
95 } |
661 | 96 |
664 | 97 SchedDefineTask1(RUN_TASK_BLOCKS,run16); |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
98 |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
99 static int |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
100 run16(SchedTask *manager, void *in, void *out) |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
101 { |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
102 #ifdef SIMPLE_TASK |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
103 WordCount *w = *(WordCount **)in; |
d753b4f6b129
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
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
106 #endif |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
107 |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
108 if (w->task_num < w->task_blocks) { |
664 | 109 if (w->size >= w->division_size) |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
110 run_tasks(manager,w,w->task_blocks, w->t_print, w->division_size); |
664 | 111 while (w->size>0) |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
112 run_tasks(manager,w,1, w->t_print, w->size); |
664 | 113 // printf("run16 last %d\n",w->task_num); |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
114 } else { |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
115 #ifdef SIMPLE_TASK |
d753b4f6b129
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, |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
117 (memaddr)&w->self,sizeof(memaddr),0,0); |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
118 #else |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
119 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
120 t_next->set_param(0,(void*)w); |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
121 #endif |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
122 w->t_print->wait_for(t_next); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
123 |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
124 run_tasks(manager,w, w->task_blocks, t_next, w->division_size); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
125 |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
126 t_next->spawn(); |
664 | 127 // printf("run16 next %d\n",w->task_num); |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
128 } |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
129 return 0; |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
130 } |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
131 |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
132 |
667
d753b4f6b129
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
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
136 |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
137 static void |
661 | 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
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
144 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); |
664 | 145 // bzero(w,sizeof(WordCount)); |
661 | 146 |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
147 w->self = w; |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
148 w->task_blocks = blocks; |
664 | 149 w->task_spwaned = 0; |
661 | 150 |
151 /*sizeはdivision_sizeの倍数にしている。*/ | |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
152 w->size = st_mmap.size; |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
153 w->file_mmap = st_mmap.file_mmap; |
661 | 154 |
155 /* 1task分のデータサイズ(byte) */ | |
666 | 156 if (w->size >= 1024*division) { |
157 w->division_size = 1024 * division;/*16kbyte*/ | |
158 } else { | |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
159 w->division_size = w->size; |
661 | 160 } |
161 | |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
162 printf("dvision_size %d\n",w->division_size); |
661 | 163 |
164 /* "word num" and "line num" */ | |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
165 w-> status_num = 2; |
661 | 166 /* taskの数 */ |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
167 w-> task_num = w->size / w->division_size; |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
168 int out_task_num = w->task_num + (w->division_size*w->task_num < w->size); |
661 | 169 |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
170 w->out_task_num = out_task_num; |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
171 printf("task_num %d\n",w->task_num); |
661 | 172 |
173 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */ | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
174 |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
175 #ifdef SIMPLE_TASK |
d753b4f6b129
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; |
d753b4f6b129
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; |
d753b4f6b129
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); |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
179 w-> out_size = 4; |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
180 #else |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
181 w-> division_out_size = 16; |
667
d753b4f6b129
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; |
661 | 183 /* out用のデータのサイズ。*/ |
669
4af9d20cf3af
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); |
4af9d20cf3af
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); |
661 | 187 |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
188 w-> pad = 2; |
667
d753b4f6b129
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
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
191 #endif |
661 | 192 printf("out size %d\n",out_size); |
193 | |
194 /*各SPEの結果を合計して出力するタスク*/ | |
195 | |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
196 #ifdef SIMPLE_TASK |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
197 t_print = manager->create_task(TASK_PRINT, |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
198 (memaddr)&w->self,sizeof(memaddr),0,0); |
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
199 #else |
661 | 200 t_print = manager->create_task(TASK_PRINT); |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
201 t_print->add_inData(w->o_data, out_size); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
202 t_print->add_inData(w->head_tail_flag, out_size); |
661 | 203 t_print->add_param(out_task_num); |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
204 t_print->add_param(w->status_num); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
205 t_print->add_param(out_task_num); |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
206 t_print->add_param(w->pad); |
667
d753b4f6b129
SimpeTask WordCount Worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
666
diff
changeset
|
207 #endif |
661 | 208 |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
209 w->t_print = t_print; |
661 | 210 |
670 | 211 for(int i = 0;i<1;i++) { |
212 /* Task を task_blocks ずつ起動する Task */ | |
213 /* serialize されていると仮定する... */ | |
214 #ifdef SIMPLE_TASK | |
215 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, | |
216 (memaddr)&w->self,sizeof(memaddr),0,0); | |
217 #else | |
218 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS); | |
219 t_exec->set_param(0,(void*)w); | |
220 #endif | |
221 t_exec->spawn(); | |
222 t_print->wait_for(t_exec); | |
223 } | |
661 | 224 |
225 t_print->spawn(); | |
226 } | |
227 | |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
228 static char* |
661 | 229 init(int argc, char **argv) |
230 { | |
231 | |
232 char *filename = 0; | |
233 | |
234 for (int i = 1; argv[i]; ++i) { | |
235 if (strcmp(argv[i], "-file") == 0) { | |
236 filename = argv[i+1]; | |
666 | 237 } else if (strcmp(argv[i], "-division") == 0) { |
238 division = atoi(argv[i+1]); | |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
239 } else if (strcmp(argv[i], "-block") == 0) { |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
240 blocks = atoi(argv[i+1]); |
672 | 241 } else if (strcmp(argv[i], "-p") == 0) { |
242 profile = 1; | |
661 | 243 } |
244 } | |
245 if (filename==0) { | |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
246 printf("usage: %s [-block 10] -file filename\n",argv[0]); |
661 | 247 exit(1); |
248 } | |
249 | |
250 return filename; | |
251 } | |
252 | |
672 | 253 |
661 | 254 int |
255 TMmain(TaskManager *manager, int argc, char *argv[]) | |
256 { | |
257 | |
258 char *filename = 0; | |
259 filename = init(argc, argv); | |
260 | |
261 if (filename < 0) { | |
262 return -1; | |
263 } | |
264 | |
265 task_init(); | |
266 run_start(manager, filename); | |
267 | |
268 return 0; | |
269 } | |
663
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
270 |
8a807e2f64f8
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
661
diff
changeset
|
271 /* end */ |