Mercurial > hg > Game > Cerium
changeset 2037:0b3d1d2863c8 draft
modify bitonic sort
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 06 Feb 2015 06:21:57 +0900 |
parents | 6fafe38d0508 |
children | a78f8360c7f9 |
files | example/bitonic_sort/main.cc example/bitonic_sort/ppe/swap.cc |
diffstat | 2 files changed, 17 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/example/bitonic_sort/main.cc Fri Feb 06 00:20:01 2015 +0900 +++ b/example/bitonic_sort/main.cc Fri Feb 06 06:21:57 2015 +0900 @@ -101,26 +101,21 @@ HTask* wait; HTask* swap; - int stage = 1; - int block = 1; - for (int i=stage; 1<<(stage-1) < length; i=stage) { - for (int j=i, k=block; 0 < j; j--, k=k/2) { + for (int i=2; i <= length; i=2*i) { + for (int j=i>>1; 0 < j; j=j>>1) { swap = manager->create_task(SWAP); swap->set_inData(0, data, length*sizeof(int*)); swap->set_outData(0, data, length*sizeof(int*)); - swap->set_param(0, (long)block); - swap->set_param(1, (long)1<<(j-1)); - swap->set_param(2, (long)k); + swap->set_param(0, (long)i); + swap->set_param(1, (long)j); swap->set_cpu(spe_cpu); swap->flip(); if (first) swap->wait_for(wait); - swap->iterate(length/2); + swap->iterate(length); wait = swap; } - stage++; - block = block<<1; first = true; } }
--- a/example/bitonic_sort/ppe/swap.cc Fri Feb 06 00:20:01 2015 +0900 +++ b/example/bitonic_sort/ppe/swap.cc Fri Feb 06 06:21:57 2015 +0900 @@ -7,24 +7,21 @@ { int* inData = (int*)s->get_input(rbuf, 0); int* outData = (int*)s->get_output(wbuf, 0); - int index = s->x; - long block = (long)s->get_param(0); - long dist = (long)s->get_param(1); - long diff = (long)s->get_param(2); + long i = (long)s->get_param(0); + long j = (long)s->get_param(1); + int k = s->x; - int spot = index/block; - index = index+diff*(index/diff); - int temp = inData[index]; + int point = j^k; + int temp = inData[k]; - if (spot%2 == 0) { - if (inData[index+dist] < inData[index]) { - outData[index] = inData[index+dist]; - outData[index+dist] = temp; + if (k < point) { + if ((i&k)==0 && inData[point] < inData[k]) { + outData[k] = inData[point]; + outData[point] = temp; } - } else { - if (inData[index] < inData[index+dist]) { - outData[index] = inData[index+dist]; - outData[index+dist] = temp; + if ((i&k)!=0 && inData[k] < inData[point]) { + outData[k] = inData[point]; + outData[point] = temp; } }