Mercurial > hg > Game > Cerium
diff 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 |
line wrap: on
line diff
--- a/example/word_count_test/main.cc Thu Dec 03 02:11:31 2009 +0900 +++ b/example/word_count_test/main.cc Thu Dec 03 04:23:36 2009 +0900 @@ -9,6 +9,7 @@ #include "TaskManager.h" #include "SchedTask.h" #include "Func.h" +#include "WordCount.h" extern void task_init(); @@ -19,20 +20,6 @@ off_t size; } st_mmap_t; -typedef struct { - int size; // remaining file size - int division_size; // for each word count task - int division_out_size; - int task_num; // remaining task count - int task_blocks; // spawn task one at a time - int status_num; - int task_spwaned; - unsigned long long *o_data; - unsigned long long *head_tail_flag; - int pad; - caddr_t file_mmap; - HTaskPtr t_print; -} WordCount; /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ @@ -86,12 +73,19 @@ { for (int j = 0; j < task_count && w->size>0; j++) { int i = w->task_spwaned++; +#ifdef SIMPLE_TASK + // printf("div %0x\n", (w->file_mmap + i*w->division_size)); + HTaskPtr t_exec = manager->create_task(TASK_EXEC, + (memaddr)(w->file_mmap + i*w->division_size), size, + (memaddr)(w->o_data + i*w->out_size), w->division_out_size); +#else HTaskPtr t_exec = manager->create_task(TASK_EXEC); if (size>w->size) size = w->size; t_exec->add_inData(w->file_mmap + i*w->division_size, size); t_exec->add_outData(w->o_data + i*w->status_num, w->division_out_size); t_exec->add_outData(w->head_tail_flag + i*w->pad, w->division_out_size); t_exec->add_param(size); +#endif t_exec->set_cpu(SPE_ANY); t_next->wait_for(t_exec); t_exec->spawn(); @@ -105,7 +99,11 @@ static int run16(SchedTask *manager, void *in, void *out) { +#ifdef SIMPLE_TASK + WordCount *w = *(WordCount **)in; +#else WordCount *w = (WordCount *)manager->get_param(0); +#endif if (w->task_num < w->task_blocks) { if (w->size >= w->division_size) @@ -114,9 +112,13 @@ run_tasks(manager,w,1, w->t_print, w->size); // printf("run16 last %d\n",w->task_num); } else { - +#ifdef SIMPLE_TASK + HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, + (memaddr)&w->self,sizeof(memaddr),0,0); +#else HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS); t_next->set_param(0,(void*)w); +#endif w->t_print->wait_for(t_next); run_tasks(manager,w, w->task_blocks, t_next, w->division_size); @@ -128,7 +130,7 @@ } -static int blocks = 192; +static int blocks = 48; static int division = 16; // in Kbyte static void @@ -141,6 +143,7 @@ WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); // bzero(w,sizeof(WordCount)); + w->self = w; w->task_blocks = blocks; w->task_spwaned = 0; @@ -163,23 +166,36 @@ w-> task_num = w->size / w->division_size; int out_task_num = w->task_num + (w->division_size*w->task_num < w->size); + w->out_task_num = out_task_num; printf("task_num %d\n",w->task_num); /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(8byte)を使用 */ + +#ifdef SIMPLE_TASK + w-> division_out_size = sizeof(unsigned long long)*4; + int out_size = w->division_out_size*out_task_num; + w->o_data = (unsigned long long *)manager->allocate(out_size); + w-> out_size = 4; +#else w-> division_out_size = 16; + int out_size = w->division_out_size*out_task_num; /* out用のデータのサイズ。*/ - int out_size = w->division_out_size*out_task_num; - w->o_data = (unsigned long long*)manager->allocate(out_size); + caddr_t p = manager->allocate(out_size*2); + w->o_data = (unsigned long long*)p //bzero(w->o_data,out_size); w-> pad = 2; - w->head_tail_flag = (unsigned long long*)manager->allocate(out_size); + w->head_tail_flag = (unsigned long long*)(p+out_size); // bzero(w->head_tail_flag,out_size); - +#endif printf("out size %d\n",out_size); /*各SPEの結果を合計して出力するタスク*/ +#ifdef SIMPLE_TASK + t_print = manager->create_task(TASK_PRINT, + (memaddr)&w->self,sizeof(memaddr),0,0); +#else t_print = manager->create_task(TASK_PRINT); t_print->add_inData(w->o_data, out_size); t_print->add_inData(w->head_tail_flag, out_size); @@ -187,13 +203,18 @@ t_print->add_param(w->status_num); t_print->add_param(out_task_num); t_print->add_param(w->pad); +#endif w->t_print = t_print; /* Task を task_blocks ずつ起動する Task */ - +#ifdef SIMPLE_TASK + HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, + (memaddr)&w->self,sizeof(memaddr),0,0); +#else HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS); t_exec->set_param(0,(void*)w); +#endif t_exec->spawn(); t_print->wait_for(t_exec);