Mercurial > hg > Game > Cerium
annotate example/many_task/ppe/QuickSort.cc @ 1538:fac06524090b draft
add gpu task wordcount. But not work print
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 16 Dec 2012 20:52:55 +0900 |
parents | 99ea7b932470 |
children | 9ccfdc408d51 |
rev | line source |
---|---|
109 | 1 #include "QuickSort.h" |
2 #include <stdio.h> | |
3 #include <string.h> | |
4 | |
5 SchedDefineTask(QuickSort); | |
6 | |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
7 static void quick_sort( Data *data, int begin, int end ) ; |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
8 |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
9 static void |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
10 swap( Data *data, int left, int right ) |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
11 { |
1513
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
12 Data tmp = data[left]; |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
13 data[left] = data[right]; |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
14 data[right] = tmp; |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
15 } |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
16 |
1514
99ea7b932470
create OpenCL test
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1513
diff
changeset
|
17 //#define USE_MEMCPY |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
18 |
1538
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
19 void |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
20 bubble_sort(Data *data, int begin, int end) |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
21 { |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
22 for (int count=0;count<end;count++) { |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
23 for (int c=end;c>count;c--) { |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
24 if (data[c].index<data[c-1].index)swap(data,c-1,c); |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
25 } |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
26 } |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
27 } |
467
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
28 static int |
839e34d0cc3c
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
29 run(SchedTask *s, void* rbuff, void* wbuff) { |
109 | 30 // copy value |
1514
99ea7b932470
create OpenCL test
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1513
diff
changeset
|
31 int begin = 0; |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
32 #if USE_SIMPLE_TASK |
936
178fbcc81fda
dead lock on spu/ppu mail
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
934
diff
changeset
|
33 int end = s->read_size()/sizeof(Data); |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
34 Data *r_data = (Data*)rbuff; |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
35 #ifdef USE_MEMCPY |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
36 Data *w_data = (Data*)wbuff; |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
37 #endif |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
38 #else |
945
9ed1c4a877ca
sort example fix ( simple task accepts one param and more compatible with old task)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
940
diff
changeset
|
39 int end = s->get_inputSize(0)/sizeof(Data); |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
40 DataPtr r_data = (DataPtr)s->get_input(0); |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
41 #ifdef USE_MEMCPY |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
42 DataPtr w_data = (DataPtr)s->get_output(0); |
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
43 #endif |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
44 #endif |
109 | 45 |
938
20beb83a5a22
dead lock still remains. zombi problem?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
936
diff
changeset
|
46 // printf("[PPE] Quick: length:%d addr->%x \n",end, (int)rbuff); |
1508 | 47 // printf("[PPE] Quick: data[0]: %ld addr->%lx\n",sizeof(r_data),(long)r_data); |
109 | 48 |
1513
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
49 quick_sort(r_data, begin, end); |
1508 | 50 |
934
83b64b7a51bd
sort fix ( not working now )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
932
diff
changeset
|
51 #ifdef USE_MEMCPY |
109 | 52 memcpy(w_data, r_data, sizeof(Data)*end); |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
53 #else |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
54 s->swap(); |
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
55 #endif |
109 | 56 |
57 return 0; | |
58 } | |
59 | |
1508 | 60 void |
61 qsort_test(Data *data, int begin, int end ) { | |
1513
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
62 quick_sort(data, begin, end-1); |
1508 | 63 } |
64 | |
65 static void | |
1513
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
66 quick_sort( Data *data, int begin, int end ) { |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
67 int stack[1024]; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
68 int sp = 0; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
69 int p; |
1538
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
70 |
1513
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
71 while (1) { |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
72 while (begin < end) { |
1538
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
73 if (end-begin <= 50) { |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
74 bubble_sort(data, begin, end); |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
75 break; |
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
76 } |
1513
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
77 int where = (begin + end) / 2; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
78 int pivot = data[where].index; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
79 data[where].index = data[begin].index; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
80 int i; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
81 p = begin; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
82 for (i=begin+1; i<=end; i++) { |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
83 if (data[i].index < pivot) { |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
84 p++; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
85 swap(data, p, i); |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
86 } |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
87 } |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
88 data[begin].index = data[p].index; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
89 data[p].index = pivot; |
109 | 90 |
1513
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
91 stack[sp++] = p + 1; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
92 stack[sp++] = end; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
93 end = p - 1; |
1508 | 94 } |
1513
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
95 if (sp == 0) return; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
96 end = stack[--sp]; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
97 begin = stack[--sp]; |
18b63e697c61
many_task/quick_sort is changed recursive to loop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1508
diff
changeset
|
98 begin = p + 1; |
1538
fac06524090b
add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
1514
diff
changeset
|
99 } |
109 | 100 } |
932
53ad3a61b40b
sort test (add swap())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
101 /* end */ |