Mercurial > hg > Members > Moririn
changeset 369:62a88864e1e2
little clean up bitonic_sort:)
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 29 Jun 2017 22:21:19 +0900 |
parents | 5506a5d61a05 |
children | 59c694722ce6 |
files | src/parallel_execution/context.h src/parallel_execution/examples/SortArray.cbc src/parallel_execution/examples/sort.cbc src/parallel_execution/examples/twice.cbc |
diffstat | 4 files changed, 17 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/context.h Thu Jun 29 21:50:01 2017 +0900 +++ b/src/parallel_execution/context.h Thu Jun 29 22:21:19 2017 +0900 @@ -294,7 +294,6 @@ int loop_counter; int loop_counter2; int loop_counter3; - int d; int sort_finish; enum Code make_array; enum Code print;
--- a/src/parallel_execution/examples/SortArray.cbc Thu Jun 29 21:50:01 2017 +0900 +++ b/src/parallel_execution/examples/SortArray.cbc Thu Jun 29 22:21:19 2017 +0900 @@ -4,7 +4,6 @@ int loop_counter; int loop_counter2; int loop_counter3; - int d; int sort_finish; __code print(struct SortArray* sortArray, __code next(...)); __code make_array(struct SortArray* sortArray, __code next(...));
--- a/src/parallel_execution/examples/sort.cbc Thu Jun 29 21:50:01 2017 +0900 +++ b/src/parallel_execution/examples/sort.cbc Thu Jun 29 22:21:19 2017 +0900 @@ -34,16 +34,16 @@ } __code print(struct SortArray* sortArray){//配列表示 - if (sortArray->sortArray->loop_counter == MAX){//ループの終了→ソートへ + if (sortArray->sortArray->loop_counter == MAX){//ループの終了→ソートへ printf("\n"); if(sortArray->sortArray->sort_finish == 1){//ソート終わってたら終了 goto meta(context, C_exit_code); } sortArray->sortArray->loop_counter = 0; - sortArray->sortArray->loop_counter2 = 0; + sortArray->sortArray->loop_counter2 = 0; goto meta(context, C_bitonic_sort); } - + printf("%d, ", sortArray->sortArray->array[sortArray->sortArray->loop_counter]->value); sortArray->sortArray->loop_counter++; goto meta(context, C_print); @@ -64,38 +64,32 @@ sortArray->sortArray->loop_counter2 = 0; goto meta(context, C_bitonic_sort); } - + goto meta(context, C_kernel2); } __code kernel2(struct SortArray* sortArray){//ソートの中身 int i = sortArray->sortArray->loop_counter3; - int up = ((i >> sortArray->sortArray->loop_counter) & 2) == 0; - int d = 1 << (sortArray->sortArray->loop_counter - sortArray->sortArray->loop_counter2); - sortArray->sortArray->d = d; - + if (i >= GET_SIZE(sortArray->sortArray->array)){//ループの終了→上のループへ sortArray->sortArray->loop_counter2++; sortArray->sortArray->loop_counter3 = 0; goto meta(context, C_kernel); } - - if ((i & d) == 0 && (sortArray->sortArray->array[i]->value > sortArray->sortArray->array[i | d]->value) == up) { - goto meta(context, C_swap); - } - - sortArray->sortArray->loop_counter3++; - goto meta(context, C_kernel2); + + goto meta(context, C_swap); } __code swap(struct SortArray* sortArray){//配列の要素を入れ替える int i = sortArray->sortArray->loop_counter3; - int d = sortArray->sortArray->d; - - struct Integer *tmp = sortArray->sortArray->array[i]; - sortArray->sortArray->array[i] = sortArray->sortArray->array[i | d]; - sortArray->sortArray->array[i | d] = tmp; - + int d = 1 << (sortArray->sortArray->loop_counter - sortArray->sortArray->loop_counter2); + int up = ((i >> sortArray->sortArray->loop_counter) & 2) == 0; + + if ((i & d) == 0 && (sortArray->sortArray->array[i]->value > sortArray->sortArray->array[i | d]->value) == up) { + struct Integer *tmp = sortArray->sortArray->array[i]; + sortArray->sortArray->array[i] = sortArray->sortArray->array[i | d]; + sortArray->sortArray->array[i | d] = tmp; + } sortArray->sortArray->loop_counter3++; goto meta(context, C_kernel2);//上位のループへ }
--- a/src/parallel_execution/examples/twice.cbc Thu Jun 29 21:50:01 2017 +0900 +++ b/src/parallel_execution/examples/twice.cbc Thu Jun 29 22:21:19 2017 +0900 @@ -150,8 +150,8 @@ task->next = C_twice; } task->idg = task->dataNum; - task->data[task->dataNum] = (union Data*)loopCounter2; - task->data[task->dataNum+1] = (union Data*)array; + task->data[task->idg] = (union Data*)loopCounter2; + task->data[task->idg+1] = (union Data*)array; task->maxIdg = task->idg + 2; task->odg = task->maxIdg; task->maxOdg = task->odg;