Mercurial > hg > Members > Moririn
changeset 366:136ce3537438
bitonic_sort's loop is work, but bitonic_sort is not work
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 29 Jun 2017 19:21:18 +0900 |
parents | ba5959d7901d |
children | 5d45b2943265 |
files | src/parallel_execution/context.h src/parallel_execution/examples/SortArray.cbc src/parallel_execution/examples/sort.cbc |
diffstat | 3 files changed, 29 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/context.h Tue Jun 27 01:29:43 2017 +0900 +++ b/src/parallel_execution/context.h Thu Jun 29 19:21:18 2017 +0900 @@ -291,10 +291,12 @@ int loop_counter2; int loop_counter3; int d; + int sort_finish; enum Code make_array; enum Code print; enum Code bitonic_sort; enum Code kernel; + enum Code kernel2; enum Code swap; }SortArray; }; // union Data end this is necessary for context generator
--- a/src/parallel_execution/examples/SortArray.cbc Tue Jun 27 01:29:43 2017 +0900 +++ b/src/parallel_execution/examples/SortArray.cbc Thu Jun 29 19:21:18 2017 +0900 @@ -5,9 +5,11 @@ 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(...)); __code bitonic_sort(struct SortArray* sortArray, __code next(...)); __code kernel(struct SortArray* sortArray, __code next(...)); + __code kernel2(struct SortArray* sortArray, __code next(...)); __code swap(struct SortArray* sortArray, __code next(...)); } SortArray;
--- a/src/parallel_execution/examples/sort.cbc Tue Jun 27 01:29:43 2017 +0900 +++ b/src/parallel_execution/examples/sort.cbc Thu Jun 29 19:21:18 2017 +0900 @@ -1,8 +1,8 @@ #include<stdio.h> #include <stdlib.h> #include "../../context.h" -#define MAX 20 #define LOGN 5 +#define MAX 1 << LOGN int main(int argc, char const* argv[]) { struct Context* main_context = NEW(struct Context); @@ -36,7 +36,7 @@ __code print(struct SortArray* sortArray){//配列表示 if (sortArray->sortArray->loop_counter == MAX){//ループの終了→ソートへ printf("\n"); - if(sortArray->sortArray->loop_counter2 > 0){//ソート終わってたら終了 + if(sortArray->sortArray->sort_finish == 1){//ソート終わってたら終了 goto meta(context, C_exit_code); } sortArray->sortArray->loop_counter = 0; @@ -52,33 +52,40 @@ __code bitonic_sort(struct SortArray* sortArray){//ソートの繰り返し if (sortArray->sortArray->loop_counter >= LOGN){//ループの終了→配列表示へ sortArray->sortArray->loop_counter = 0; + sortArray->sortArray->sort_finish = 1; goto meta(context, C_print); } goto meta(context, C_kernel); } -__code kernel(struct SortArray* sortArray){//ソートの中身 - int i = sortArray->sortArray->loop_counter3; - int d = 0; - int up; - +__code kernel(struct SortArray* sortArray){//繰り返し2 if (sortArray->sortArray->loop_counter2 > sortArray->sortArray->loop_counter){//ループの終了→上のループへ sortArray->sortArray->loop_counter++; + sortArray->sortArray->loop_counter2 = 0; goto meta(context, C_bitonic_sort); } - sortArray->sortArray->d = 1 << (sortArray->sortArray->loop_counter - sortArray->sortArray->loop_counter2); - d = sortArray->sortArray->d; + 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 = (sortArray->sortArray->loop_counter - sortArray->sortArray->loop_counter2); + sortArray->sortArray->d = d; - if (i < GET_SIZE(sortArray->sortArray->array)){ - up = ((i >> sortArray->sortArray->loop_counter) & 2) == 0; - if ((i & d) == 0 && (sortArray->sortArray->array[i] > sortArray->sortArray->array[i | d]) == up) {//ここ入ってない - goto meta(context, C_swap); - } + if (i >= GET_SIZE(sortArray->sortArray->array)){//ループの終了→上のループへ + sortArray->sortArray->loop_counter2++; + sortArray->sortArray->loop_counter3 = 0; + goto meta(context, C_kernel); } - sortArray->sortArray->loop_counter2++; - goto meta(context, C_kernel); + if ((i & d) == 0 && (sortArray->sortArray->array[i] > sortArray->sortArray->array[i | d]) == up) { + goto meta(context, C_swap); + } + + sortArray->sortArray->loop_counter3++; + goto meta(context, C_kernel2); } __code swap(struct SortArray* sortArray){//配列の要素を入れ替える @@ -88,7 +95,7 @@ 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_kernel);//上位のループへ + goto meta(context, C_kernel2);//上位のループへ }