Mercurial > hg > Members > kono > Cerium
comparison example/word_count_test/main.cc @ 664:7405d92733a8
word count
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2009 00:20:28 +0900 |
parents | 8a807e2f64f8 |
children | 4470ff271c5a |
comparison
equal
deleted
inserted
replaced
663:8a807e2f64f8 | 664:7405d92733a8 |
---|---|
24 int division_size; // for each word count task | 24 int division_size; // for each word count task |
25 int division_out_size; | 25 int division_out_size; |
26 int task_num; // remaining task count | 26 int task_num; // remaining task count |
27 int task_blocks; // spawn task one at a time | 27 int task_blocks; // spawn task one at a time |
28 int status_num; | 28 int status_num; |
29 int task_spwaned; | |
29 unsigned long long *o_data; | 30 unsigned long long *o_data; |
30 unsigned long long *head_tail_flag; | 31 unsigned long long *head_tail_flag; |
31 int pad; | 32 int pad; |
32 caddr_t file_mmap; | 33 caddr_t file_mmap; |
33 HTaskPtr t_print; | 34 HTaskPtr t_print; |
81 } | 82 } |
82 | 83 |
83 static void | 84 static void |
84 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) | 85 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) |
85 { | 86 { |
86 for (int i = 0; i < task_count && w->size >= w->division_size; i++) { | 87 for (int j = 0; j < task_count && w->size>0; j++) { |
88 int i = w->task_spwaned++; | |
87 HTaskPtr t_exec = manager->create_task(TASK_EXEC); | 89 HTaskPtr t_exec = manager->create_task(TASK_EXEC); |
90 if (size>w->size) size = w->size; | |
88 t_exec->add_inData(w->file_mmap + i*w->division_size, size); | 91 t_exec->add_inData(w->file_mmap + i*w->division_size, size); |
89 t_exec->add_outData(w->o_data + i*w->status_num, w->division_out_size); | 92 t_exec->add_outData(w->o_data + i*w->status_num, w->division_out_size); |
90 t_exec->add_outData(w->head_tail_flag + i*w->pad, w->division_out_size); | 93 t_exec->add_outData(w->head_tail_flag + i*w->pad, w->division_out_size); |
91 t_exec->add_param(size); | 94 t_exec->add_param(size); |
92 t_exec->set_cpu(SPE_ANY); | 95 t_exec->set_cpu(SPE_ANY); |
95 w->size -= size; | 98 w->size -= size; |
96 w->task_num--; | 99 w->task_num--; |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 SchedDefineTask1(RUN_TASK_16,run16); | 103 SchedDefineTask1(RUN_TASK_BLOCKS,run16); |
101 | 104 |
102 static int | 105 static int |
103 run16(SchedTask *manager, void *in, void *out) | 106 run16(SchedTask *manager, void *in, void *out) |
104 { | 107 { |
105 WordCount *w = (WordCount *)manager->get_param(1); | 108 WordCount *w = (WordCount *)manager->get_param(0); |
106 | 109 |
107 if (w->task_num < w->task_blocks) { | 110 if (w->task_num < w->task_blocks) { |
108 if (w->size > w->division_size) | 111 if (w->size >= w->division_size) |
109 run_tasks(manager,w,w->task_blocks, w->t_print, w->division_size); | 112 run_tasks(manager,w,w->task_blocks, w->t_print, w->division_size); |
110 if (w->size>0 && w->size < w->division_size) | 113 while (w->size>0) |
111 run_tasks(manager,w,1, w->t_print, w->size); | 114 run_tasks(manager,w,1, w->t_print, w->size); |
115 // printf("run16 last %d\n",w->task_num); | |
112 } else { | 116 } else { |
113 | 117 |
114 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS); | 118 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS); |
115 t_next->set_param(0,(void*)w); | 119 t_next->set_param(0,(void*)w); |
116 w->t_print->wait_for(t_next); | 120 w->t_print->wait_for(t_next); |
117 | 121 |
118 run_tasks(manager,w, w->task_blocks, t_next, w->division_size); | 122 run_tasks(manager,w, w->task_blocks, t_next, w->division_size); |
119 | 123 |
120 t_next->spawn(); | 124 t_next->spawn(); |
125 // printf("run16 next %d\n",w->task_num); | |
121 } | 126 } |
122 return 0; | 127 return 0; |
123 } | 128 } |
124 | 129 |
125 | 130 |
131 HTaskPtr t_print; | 136 HTaskPtr t_print; |
132 | 137 |
133 st_mmap_t st_mmap; | 138 st_mmap_t st_mmap; |
134 st_mmap = my_mmap(filename); | 139 st_mmap = my_mmap(filename); |
135 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); | 140 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); |
141 // bzero(w,sizeof(WordCount)); | |
136 | 142 |
137 w->task_blocks = blocks; | 143 w->task_blocks = blocks; |
144 w->task_spwaned = 0; | |
138 | 145 |
139 /*sizeはdivision_sizeの倍数にしている。*/ | 146 /*sizeはdivision_sizeの倍数にしている。*/ |
140 w->size = st_mmap.size; | 147 w->size = st_mmap.size; |
141 w->file_mmap = st_mmap.file_mmap; | 148 w->file_mmap = st_mmap.file_mmap; |
142 | 149 |
161 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */ | 168 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */ |
162 w-> division_out_size = 16; | 169 w-> division_out_size = 16; |
163 /* out用のデータのサイズ。*/ | 170 /* out用のデータのサイズ。*/ |
164 int out_size = w->division_out_size*out_task_num; | 171 int out_size = w->division_out_size*out_task_num; |
165 w->o_data = (unsigned long long*)manager->allocate(out_size); | 172 w->o_data = (unsigned long long*)manager->allocate(out_size); |
173 //bzero(w->o_data,out_size); | |
166 | 174 |
167 w-> pad = 2; | 175 w-> pad = 2; |
168 w->head_tail_flag = (unsigned long long*)manager->allocate(out_size); | 176 w->head_tail_flag = (unsigned long long*)manager->allocate(out_size); |
177 // bzero(w->head_tail_flag,out_size); | |
169 | 178 |
170 printf("out size %d\n",out_size); | 179 printf("out size %d\n",out_size); |
171 | 180 |
172 /*各SPEの結果を合計して出力するタスク*/ | 181 /*各SPEの結果を合計して出力するタスク*/ |
173 | 182 |