diff example/bitonic_sort/main.cc @ 2040:bc010492ade4 draft

add cuda task with bitonic sort.
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 10 Mar 2015 17:41:12 +0900
parents a78f8360c7f9
children
line wrap: on
line diff
--- a/example/bitonic_sort/main.cc	Thu Feb 12 17:04:03 2015 +0900
+++ b/example/bitonic_sort/main.cc	Tue Mar 10 17:41:12 2015 +0900
@@ -25,7 +25,7 @@
 int length = 1024;
 int* data;
 
-bool flag = false;
+bool wait_flag = false;
 
 static double
 getTime()
@@ -101,24 +101,27 @@
 
     HTask* wait;
     HTask* swap;
+    bool lastOne = false;
 
     for (int i=2; i <= length; i=2*i) {
-        bool first = true;
+        long first = 1;
+        lastOne = (length <= i*2) ? true : false;
         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)j);
-            swap->set_param(1, (bool)first);
+            swap->set_param(1, (long)first);
             swap->set_cpu(spe_cpu);
-            swap->flip();
-            if (flag)
+            if (!(lastOne && !(0 < (j>>1))))
+                swap->flip();
+            if (wait_flag)
                 swap->wait_for(wait);
             swap->iterate(length/2);
-            first = false;
+            first = 0;
             wait = swap;
         }
-        flag = true;
+        wait_flag = true;
     }
 }
     
@@ -140,6 +143,6 @@
 {
     ed_time = getTime();
     printf("%0.6f\n",ed_time-st_time);
-    //print();
+    //    print();
     check_data();
 }