Mercurial > hg > Game > Cerium
changeset 935:11b19708e613 draft
-a option for sort
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 31 Jul 2010 03:13:24 +0900 |
parents | 83b64b7a51bd |
children | 178fbcc81fda |
files | example/many_task/Func.h example/many_task/main.cc example/many_task/sort.cc example/many_task/task_init.cc |
diffstat | 4 files changed, 27 insertions(+), 92 deletions(-) [+] |
line wrap: on
line diff
--- a/example/many_task/Func.h Sat Jul 31 02:45:21 2010 +0900 +++ b/example/many_task/Func.h Sat Jul 31 03:13:24 2010 +0900 @@ -1,4 +1,5 @@ enum { #include "SysTasks.h" QUICK_SORT, + RESTART, };
--- a/example/many_task/main.cc Sat Jul 31 02:45:21 2010 +0900 +++ b/example/many_task/main.cc Sat Jul 31 03:13:24 2010 +0900 @@ -11,6 +11,8 @@ // sort.cc extern int data_length; extern DataPtr data; +extern int all; +int all = 0; // 計測用 static double st_time; @@ -53,6 +55,9 @@ if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) { length = atoi(argv[++i]); } + if (strcmp(argv[i], "-a") == 0 ) { + all = 1; + } }
--- a/example/many_task/sort.cc Sat Jul 31 02:45:21 2010 +0900 +++ b/example/many_task/sort.cc Sat Jul 31 03:13:24 2010 +0900 @@ -11,6 +11,8 @@ static int data_length; static int cpuNum; +extern int all; + /** * 一つの block にある data の数が MAX_BLOCK_SIZE 超えないような * len の分割数を返す @@ -37,109 +39,30 @@ HTaskPtr *fsort; HTaskPtr *bsort; - -#define ALL_TASK - -#ifdef ALL_TASK - -static void -sort_start(SchedTask *manager) -{ - int split_num = get_split_num(data_length, cpuNum); // data の分割数 - int half_num = split_num-1; - static int sort_count = split_num; // sort 完了に必要な回数 - - // 一つのタスクで sort する data 数 - int block_num = (data_length + split_num -1)/split_num; - int half_block_num = block_num/2; - - int last_block_num = data_length - (split_num-1)*block_num; - int last_half_block_num = half_block_num+(last_block_num/2); - - while (--sort_count > 0) { - - for (int i = 0; i < split_num-1; i++) { - fsort[i] = manager->create_task(QUICK_SORT, - (memaddr)&data[i*block_num], sizeof(Data)*block_num, - (memaddr)&data[i*block_num], sizeof(Data)*block_num); - if (i>0 && bsort[i-1]) { - fsort[i]->wait_for(bsort[i-1]); - } - if (i<split_num-2 && bsort[i]) { - fsort[i]->wait_for(bsort[i]); - } - fsort[i]->set_cpu(SPE_ANY); - } - - // 最後の block は端数なので last_block_num を使う - { - int i = split_num-1; +int split_num; - fsort[i] = manager->create_task(QUICK_SORT, - (memaddr)&data[i*block_num], sizeof(Data)*last_block_num, - (memaddr)&data[i*block_num], sizeof(Data)*last_block_num); - if (i>0 && bsort[i-1]) { - fsort[i]->wait_for(bsort[i-1]); - } - fsort[i]->set_cpu(SPE_ANY); - } - - if (split_num > 1) { - - for (int i = 0; i < half_num-1; i++) { - bsort[i] = manager->create_task(QUICK_SORT, - (memaddr)&data[i*block_num+half_block_num], sizeof(Data)*block_num, - (memaddr)&data[i*block_num+half_block_num], sizeof(Data)*block_num); - bsort[i]->set_cpu(SPE_ANY); - } - - { - int i = half_num-1; - - bsort[i] = manager->create_task(QUICK_SORT, - (memaddr)&data[i*block_num+half_block_num], sizeof(Data)*last_half_block_num, - (memaddr)&data[i*block_num+half_block_num], sizeof(Data)*last_half_block_num); - bsort[i]->set_cpu(SPE_ANY); - } - - for (int i = 0; i < half_num; i++) { - bsort[i]->wait_for(fsort[i]); - bsort[i]->wait_for(fsort[i+1]); - bsort[i]->spawn(); - } - } - - for (int i = 0; i < split_num; i++) { - fsort[i]->spawn(); - } - } -} - -#else /** * btask が全て終了したら、再び sort_start を実行する * @param d 生成された btask の数 */ -static void + +SchedDefineTask1(RESTART, sort_restart ); + +static int sort_restart(SchedTask *s, void *d, void *e) { - static int cnt = 0; static int ccc = 0; - long max = (long)d; - if (++cnt == max) { - printf("restarted %d %% %ld\n",ccc++,max); - cnt = 0; - sort_start(s); - } + printf("restarted %d %% %d\n",ccc++,split_num); + sort_start(s); + return 0; } #ifdef USE_SIMPLE_TASK static void sort_start(SchedTask *manager) { - int split_num = get_split_num(data_length, cpuNum); // data の分割数 int half_num = split_num-1; static int sort_count = split_num; // sort 完了に必要な回数 @@ -207,10 +130,12 @@ } } + HTaskPtr restart = manager->create_task(RESTART,0,0,0,0); for (int i = 0; i < split_num; i++) { - fsort[i]->set_post(sort_restart, (void*)(half_num),(void*)manager); + if (!all) restart->wait_for(fsort[i]); fsort[i]->spawn(); } + restart->spawn(); } #else @@ -218,7 +143,6 @@ static void sort_start(SchedTask *manager) { - int split_num = get_split_num(data_length, cpuNum); // data の分割数 int half_num = split_num-1; static int sort_count = split_num; // sort 完了に必要な回数 @@ -296,13 +220,15 @@ } } + HTask restart = create_task(RESTART,0,0,0,0); for (int i = 0; i < split_num; i++) { - fsort[i]->set_post(sort_restart, (void*)(half_num),(void*)manager); + if (!all) restart->wait_for(fsort[i]); fsort[i]->spawn(); } + restart->spawn(); + } #endif -#endif void check_data() { @@ -317,6 +243,7 @@ if (flag) printf("Data are sorted\n"); } + void sort_init(SchedTask *manager, void *a, void *b) { @@ -326,7 +253,7 @@ data = (DataPtr)manager->allocate(sizeof(Data)*length); data_length = length; - int split_num = get_split_num(data_length, cpuNum); // data の分割数 + split_num = get_split_num(data_length, cpuNum); // data の分割数 int half_num = split_num-1; fsort = (HTaskPtr*)manager->allocate(sizeof(HTaskPtr)*split_num); bsort = (HTaskPtr*)manager->allocate(sizeof(HTaskPtr)*half_num);
--- a/example/many_task/task_init.cc Sat Jul 31 02:45:21 2010 +0900 +++ b/example/many_task/task_init.cc Sat Jul 31 03:13:24 2010 +0900 @@ -2,9 +2,11 @@ #include "Scheduler.h" SchedExternTask(QuickSort); +SchedExternTask(RESTART); void task_init(void) { SchedRegisterTask(QUICK_SORT, QuickSort); + SchedRegister(RESTART); }