comparison example/word_count/main.cc @ 970:33630c6ff445

change pipeline and TaskArray fast
author Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
date Thu, 26 Aug 2010 20:38:06 +0900
parents 0a6c5ee89a4c
children d093d601fc14
comparison
equal deleted inserted replaced
968:0a6c5ee89a4c 970:33630c6ff445
15 15
16 int all = 0; 16 int all = 0;
17 int use_task_array = 1; 17 int use_task_array = 1;
18 int use_compat = 0; 18 int use_compat = 0;
19 int array_task_num = 8; 19 int array_task_num = 8;
20 int spe_num = 1;
20 21
21 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-file filename]\n"; 22 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-file filename]\n";
22 23
23 typedef struct { 24 typedef struct {
24 caddr_t file_mmap; 25 caddr_t file_mmap;
80 if (task_count < array_task_num) { 81 if (task_count < array_task_num) {
81 array_task_num = task_count; 82 array_task_num = task_count;
82 if (task_count<=0) return; 83 if (task_count<=0) return;
83 } 84 }
84 85
86
87 if (use_task_array) {
88
89 int spl = spe_num * array_task_num;
90 int loop = (task_count + spl - 1) / spl;
91
92 for (int i = 0; i < loop; i += 1) {
93
94 if (spl > w->task_num) {
95 spe_num = 1;
96 array_task_num = w->task_num;
97 }
98
99
100 HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num);
101 Task **t_exec = (Task**)manager->allocate(sizeof(Task*)*spe_num);
102
103 for (int k = 0; k < spe_num; k++) {
104 task_array[k] = manager->create_task_array(TASK_EXEC,array_task_num,0,1,1);
105 t_exec[k] = 0;
106 if (all) {
107 w->t_print->wait_for(task_array[k]);
108 } else {
109 t_next->wait_for(task_array[k]);
110 }
111 }
112
113
114 for (int j = 0; j < array_task_num; j++) {
115 for (int k = 0; k < spe_num; k++) {
116
117 int a = w->task_spwaned++;
118
119 if (w->size < size) size = w->size;
120
121 t_exec[k] = task_array[k]->next_task_array(TASK_EXEC,t_exec[k]);
122 t_exec[k]->set_inData(0,w->file_mmap + a*w->division_size, size);
123 t_exec[k]->set_outData(0,w->o_data + a*w->out_size, w->division_out_size);
124
125 w->size -= size;
126 w->task_num--;
127 }
128 }
129
130 for (int k = 0; k < spe_num; k++) {
131 task_array[k]->spawn_task_array(t_exec[k]->next());
132 task_array[k]->set_cpu(SPE_ANY);
133 task_array[k]->spawn();
134 }
135
136 }
137
138 return;
139
140 }
141
142
85 for (int i = 0; i < task_count; i += array_task_num) { 143 for (int i = 0; i < task_count; i += array_task_num) {
86 144
87 HTask *task_array; 145 HTask *h_exec = 0;
88 if (use_task_array) {
89 int task_num = (w->size+size-1)/size;
90 if (task_num>array_task_num) task_num = array_task_num;
91 task_array = manager->create_task_array(TASK_EXEC,task_num,0,1,1);
92 if (!all) {
93 t_next->wait_for(task_array);
94 } else {
95 w->t_print->wait_for(task_array);
96 }
97 }
98
99 Task *t_exec = 0;
100 HTask *h_exec = 0;
101 for (int j = 0; j < array_task_num; j++) { 146 for (int j = 0; j < array_task_num; j++) {
102 int i = w->task_spwaned++; 147 int i = w->task_spwaned++;
103 if (w->size < size) size = w->size; 148 if (w->size < size) size = w->size;
104 if (size==0) break; 149 if (size==0) break;
105 if (use_task_array) { 150
106 t_exec = task_array->next_task_array(TASK_EXEC,t_exec); 151 if (use_compat) {
107 t_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
108 t_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
109 } else if (use_compat) {
110 h_exec = manager->create_task(TASK_EXEC); 152 h_exec = manager->create_task(TASK_EXEC);
111 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size); 153 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
112 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); 154 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
113 155
114 t_next->wait_for(h_exec); 156 if (all) {
115 157 w->t_print->wait_for(h_exec);
158 } else {
159 t_next->wait_for(h_exec);
160 }
161
116 h_exec->set_cpu(SPE_ANY); 162 h_exec->set_cpu(SPE_ANY);
117 h_exec->spawn(); 163 h_exec->spawn();
164
118 } else { 165 } else {
119 h_exec = manager->create_task(TASK_EXEC, 166 h_exec = manager->create_task(TASK_EXEC,
120 (memaddr)(w->file_mmap + i*w->division_size), size, 167 (memaddr)(w->file_mmap + i*w->division_size), size,
121 (memaddr)(w->o_data + i*w->out_size), w->division_out_size); 168 (memaddr)(w->o_data + i*w->out_size), w->division_out_size);
122 t_next->wait_for(h_exec); 169
170 if (all) {
171 w->t_print->wait_for(h_exec);
172 } else {
173 t_next->wait_for(h_exec);
174 }
175
123 h_exec->set_cpu(SPE_ANY); 176 h_exec->set_cpu(SPE_ANY);
124 h_exec->spawn(); 177 h_exec->spawn();
125 } 178 }
126 w->size -= size; 179 w->size -= size;
127 w->task_num--; 180 w->task_num--;
128 } 181 }
129 if (use_task_array) { 182
130 task_array->spawn_task_array(t_exec->next()); 183 }
131 task_array->set_cpu(SPE_ANY); 184
132 task_array->spawn();
133 } else {
134 //if (!all) t_next->wait_for(h_exec);
135 }
136 }
137 } 185 }
138 186
139 /** 187 /**
140 * このTaskは、PPE上で実行されるので、並列に実行されることはない 188 * このTaskは、PPE上で実行されるので、並列に実行されることはない
141 * 二つ実行されていて、Task が足りなくなることがないようにしている。 189 * 二つ実行されていて、Task が足りなくなることがないようにしている。
267 } else if (strcmp(argv[i], "-s") == 0) { 315 } else if (strcmp(argv[i], "-s") == 0) {
268 use_task_array = 0; 316 use_task_array = 0;
269 use_compat = 0; 317 use_compat = 0;
270 } else if (strcmp(argv[i], "-anum") == 0) { 318 } else if (strcmp(argv[i], "-anum") == 0) {
271 array_task_num = atoi(argv[i+1]); 319 array_task_num = atoi(argv[i+1]);
320 } else if (strcmp(argv[i], "-cpu") == 0) {
321 spe_num = atoi(argv[i+1]);
272 } 322 }
273 } 323 }
274 if (filename==0) { 324 if (filename==0) {
275 puts(usr_help_str); 325 puts(usr_help_str);
276 exit(1); 326 exit(1);